Black boxes with tons of magic are great if you need to do exactly that one thing that creators had in mind. When you need it to work a little bit different you're usually either just out of luck, or the added flexibility makes whole api very complex (and usually buggy, as it goes hand in hand). It's just super hard to make things very high-level and simple, while still flexible enough.
Having a number of simpler functionalities that you're free to compose any way you like is for me preferred approach anytime. Most of the things that you mention can be solved with fairly simple wrapper libs doing just one thing (tracking state of connection, tracking errors, batching requests, etc.). Perhaps not in a perfectly reusable way, but good enough to allow easy recycling from project to project, and it's way easier to use and debug and adjust than if we had one huge built-in service object to handle it all.
There are a few black boxes most people are very happy not to peek into; Having these black boxes is a huge productivity win:
* Compilers
* Garbage Collection
* OS Kernels
* File systems
* Docker
* App Stores / package managers
* Infrastructure as code frameworks (i.e. terraform)
* JS Frontend frameworks
I think there's three things at work here: 1. Familarity with treating item X as a black box (High for compilers, low for infrastructure as code). 2. Maturity of the interfaces (High for compilers, low for infrastructure as code). 3. Relevance of the details for your use case / business context.
> Having a number of simpler functionalities that you're free to compose any way you like is for me preferred approach anytime. Most of the things that you mention can be solved with fairly simple wrapper libs doing just one thing
I totally agree: That's how I imagine how the magic functions are defined.
> Black boxes with tons of magic are great if you need to do exactly that one thing that creators had in mind.
This totally depends what your business context is. For most companies, dealing with CORS in HTTP requests is very far from their business domain. Still, developers spend a lot of time configuring and building endpoints, API clients, etc. at a low level of abstraction.
And in the frontend component you should be able to use it immediately and it would be correctly typed without having to duplicate types or anything. And if function is not complete yet it will not render the component before.
This should be instead of REST and Graphql, both of which have many issues imo.
Why? REST doesn't have anything to say about this. You can design your application however you prefer, and publish input and output specs however you prefer, without tailoring your application to the HTTP layer.
It could work with REST underneath or REST being auto generated based off your function names, but you shouldn't have to deal with that. And REST in general would probably not be optimal to transfer the data here.
GET /tasks?whatever=filters
I agree the part that wires up the HTTP behavior should be minimal and mostly uninvolved with your application logic. (I’m actually working on such a beast!).Let's say you now want to add a filter for frontend where you can choose multiple dynamic fields and their conditions can be either greater than, equal, or IN some values, I think you get the gist.
You then will have to do it something like that tasks?status=in:todo,progress
Or status=todo&status=done But then you suddenly need greaterThan query. Are you going to do tasks?priority=gt:5 for example?
Or things like that. And you have to worry if this even adheres to URL standards. Things eventually get so messy. And you are very constrained in everything you do.
And how do you typecheck all of that? Also all of this is just error prune, you have to write documentation for it and every REST api is a little bit different, people often mess up when naming the urls etc.
I’m not sure I even follow what you’re proposing. That URLs are insufficient for nested structural queries or that you want URL queries and POSTed JSON queries (which is not even REST) at the same time?
If it’s the former, this isn’t something a client or server should need to worry about. Server tools should make defining the API simple in the native language, and generate documentation which can provide client SDKs (again I’m building such a tool).
> Let's say you now want to add a filter for frontend where you can choose multiple dynamic fields and their conditions can be either greater than, equal, or IN some values, I think you get the gist. [...] status=in:todo,progress [...] status=todo&status=done
The most common way this is handled is either your second syntax or status[]=todo&status[]=done (or even with explicit indexes) to make clear it’s multiple values. AFAIK most major URL (de)serializers handle this automatically with no developer effort.
> priority=gt:5
Why not priority=>5? Again a library can trivially handle simple expressions like this, you don’t have to.
> And how do you typecheck all of that?
This is something the library should handle too. And it’s something I know about because I’ve built it (and again I’m working on one I can make open source). For a hint of how this might look and some prior art, check out io-ts.
> Also all of this is just error prune, you have to write documentation for it and every REST api is a little bit different, people often mess up when naming the urls etc
I bet you can already predict it, but the library should take care of this and I’m building it.
None of this should be so messy or so much work for people developing services. You got that right! But that doesn’t mean REST is bad, it means the tools for building and consuming REST services aren’t very mature. But they certainly can be.
BTW IMO most of BI type stuff could be solved by just allowing direct SQL, but for this DBs would need to be written without buffer overflow bugs etc. I would love to have SQLite that has easy data-at-rest encryption amd that supports access control.
From how I read it, this the post is not specifically about JS and a discussion of the specific technologies mentioned but rather concerned with the following very general situation:
1. There's a user sitting in front of a browser.
2. There's a backend server providing data and points of interaction with that data.
I think the central point of the post now is that we don't have a satisfying technical solution for this situation.
Let's take a look at one of the points you mentioned. Maybe you might find there's actually some valid points in the post and give it a more favourable reread.
> UX when fetching data: What does that have to do with any of the above?
Here, the author of the post writes: "It’s a big burden for engineers to have to manually add loading spinners and error states, and engineers often forget."
I think it's more or less clear how you could implement this using only plain vanilla js. Cumbersome but doable: A very manual, imperative process.
Now let's envision a technology from a possible future:
Imagine this was everything you had write in your code to get the following:* state gets automatically loaded when the first instance of the component is created
* updates are automatically visualized in the client based on the internals of the declaration in the renderer
* you don't have to specify if the updates are done by polling, websockets or whatever: the two magic methods figure this out by themselves.
* you don't have to specify how the data is fetched in the first place. giving the a URI to the `createMagicDataSource` function is enough.
* additional instances of the component don't fetch the data again
* updates are efficient: the sync method only exchanges exactly the data required, only the minimal visual updates are performed
* marking feeds as "seen" by the user is also done by magic and syncs across devices (same for other non-ephemeral ui state).
Now: And I'm sure you'd agree that we are not there yet technologically. But I hope you agree that this would be really nice.