The more I work on #ONI, which is basically a web components frontend for an as basic as possible #ActivityPub client to server service, the more I realize I'm just not built for JavaScript programming.
-
The more I work on #ONI, which is basically a web components frontend for an as basic as possible #ActivityPub client to server service, the more I realize I'm just not built for JavaScript programming.
Despite having put in the hours every day for a number of months, the whole Promise paradigm just doesn't seem to click for me.
Now I'm struggling to create a throbber component (easy) while fetches happen in the background (easy) and then have it replaced (not easy) by actual content (easy).
😱 Gaaah!!!
-
The more I work on #ONI, which is basically a web components frontend for an as basic as possible #ActivityPub client to server service, the more I realize I'm just not built for JavaScript programming.
Despite having put in the hours every day for a number of months, the whole Promise paradigm just doesn't seem to click for me.
Now I'm struggling to create a throbber component (easy) while fetches happen in the background (easy) and then have it replaced (not easy) by actual content (easy).
😱 Gaaah!!!
@mariusor FWIW, I'm working on a similar thing, and I've settled into a pattern like this - the component has a spinner, a viewer, and a no-data message, then have a dataBind() method like:
```
dataBind(data, binder) {
if (data) {
this.#spinner.style.display = 'none';
this.#viewer.style.display = null;
this.#noData.style.display = 'none';
} else {
this.#spinner.style.display = 'none';
this.#viewer.style.display = 'none';
this.#noData.style.display = null;
}
}
``` -
@mariusor FWIW, I'm working on a similar thing, and I've settled into a pattern like this - the component has a spinner, a viewer, and a no-data message, then have a dataBind() method like:
```
dataBind(data, binder) {
if (data) {
this.#spinner.style.display = 'none';
this.#viewer.style.display = null;
this.#noData.style.display = 'none';
} else {
this.#spinner.style.display = 'none';
this.#viewer.style.display = 'none';
this.#noData.style.display = null;
}
}
```@OpinionatedGeek litjs has an idiomatic way of achieving this kind of logic.
It has an `until(promise, fallback)` function which waits for the promise to resolve and display fallback until then.
Even with this simple setup I still get issues. :D
It's definitely a "me" problem. I'm holding it wrong somehow, but I haven't seen any examples in the wild of "holding it right".