Live data from Hacker News

Show HN: Aberdeen – An elegant approach to reactive UIs

aberdeenjs.org

81–90 of 138 posts

Re: Show HN: Aberdeen – An elegant approach to reactive UIs

#81

Earlier quoted context omitted.

I don't particularly like how control logic needs to be embedded within JSX using ?ternary : operators and .map(() => stuff) within the HTML. Also, in order to transform JSX into individual rerunnable functions, we'd need a whole different transpiler. I like being able to code browser-runnable JavaScript directly. To each their own. :-)

re: syntax, I agree, it's stopped me from ever trying React/JSX-based frameworks, which I am sure is an over-reaction. I have a POC syntax extension (babel parser fork) I named JSXG where I introduced "generator elements" which treats the body of the element as a JS generator function that yields JSX elements. The simple/naive implementation of just running the generator was okay, but I (perhaps prematurely) worried…

Ah, the roadblocks are coming back to me.

The first was using Edit: The other premature concern/feature was the ability to have a for loop NOT render to an array and rather be inline.

Normaly

    for (...) { yield ... }
    // becomes
    [[..., ..., ...]]
But I added a mechanism using string directives that would inline it:

    "use jsxg:inline"
    for (...) { yield ... }
    // becomes
    [..., ..., ...]

Re: Show HN: Aberdeen – An elegant approach to reactive UIs

#82
post #31

You may have something, but your first example is so complex I immediately gave up. Maybe start with something super small like a counter.

You're right, of course! I'll do that, thanks!

Done! https://aberdeenjs.org/#examples

Re: Show HN: Aberdeen – An elegant approach to reactive UIs

#84
I remember the concept of the virtual dom had to be explained very carefully so people understood why it led to more efficiency when rendering (e.g.) scrolling content.

Is there a technical trick that one takes that can beat a virtual dom use case? What is it?

Re: Show HN: Aberdeen – An elegant approach to reactive UIs

#85
post #60

Congrats on making it to V1! Though not immediately obvious, there's a lot of parallels to be drawn between this and solid.js (proxy is a sort of `signal` right?, no virtual dom) - I'd be curious what you'd say are the primary benefits of this library over something like Solid.js? I gotta turn a little negative here... Off the bat, regarding the first point in the "Why use Aberdeen?" section, I have a few nit-picks:…

Thanks!

Yes, there's some similarity to Solid.js, but also two big differences:

1. A Solid.js signal contains a single atomic value that can be subscribed to, while an Aberdeen proxy can wrap around a complex object (containing arrays containing objects, etc), and subscribe to only the primitive values that were read.

2. If I understand correctly, Solid.js can only redraw entire components (which may not be great at it, like Aberdeen, doesn't use a VDOM), while Aberdeen creates observer scopes every time you nest DOM elements (or manually, if that is not enough for some specific case).

So Aberdeen is more finegrained on both counts. And there's no need for createMemo and createEffect.

Re "Elegant and simple": the Aberdeen internals are far from simple, but I think its semantics are very simple to understand. Especially when compared to monsters like React. But I'd settle for easy. :-)

> "And in many ways, it's more natural to express DOM structures as JSX-ish components."

Yeah, until you want to add some loops and conditionals in there. That's what regular programming languages are really good at. But it's a trade-off for sure.

> "this is just plain gaslighting" ... " and you end up having to solve all the same issues as with all those libraries"

I don't think that's the case. In my (admittedly colored) experience, Aberdeen allows you to do the same things while having to learn far fewer concepts.

But reading back my text, the claim could have better just said that, as replacing a ton of complex concepts with a ton of different but equally complex concepts is not better. I've updated the site.

> You are pretending that this library does away with a lot of things that are the bread and bones of other UI libraries but then your UI library still needs all those things.

My claim is that we don't, in fact, need all those things. As Aberdeen takes a rather different approach, we do of course need some other things (as you pointed out earlier), but I believe this approach allows us to have less of them.

Re "Diamond problem": I haven't heard the term before, but Aberdeen solves this by a) batching updates (using a setTimeout 0 by default) and b) rerunning all dirtied scopes in the order that they were initially created.

> but trying to frame it in a way that it is superior to using something like JSX seems like gaslighting to me.

I'd be happy to add more downsides to the why-NOT-to-use-this list, but my rose colored glasses seem to prevent me from articulating something that makes sense there. :-)

Re "TypeScript" safety: It says `"strict": true` in the config file. Any other settings you'd want on? Also, the lib has 100% test coverage, if you're into that sort of thing! :-)

Re: Show HN: Aberdeen – An elegant approach to reactive UIs

#86

I remember the concept of the virtual dom had to be explained very carefully so people understood why it led to more efficiency when rendering (e.g.) scrolling content. Is there a technical trick that one takes that can beat a virtual dom use case? What is it?

Yes, it's an easy trick: just rerender the tiny parts of the DOM that actually need to change. Like Svelte does, only with run-time magic, instead of compile-time magic.

Re: Show HN: Aberdeen – An elegant approach to reactive UIs

#87
post #61

Earlier quoted context omitted.

The problem is that JSX transpilers will put child nodes in an array, instead of in an anonymous function, meaning there is no easy way (without transpiler magic) to rerender just a part of the component. This JSX: Welcome {data.enabled ? : "disabled"} Which becomes this with Babel: _jsx("section", {children: [ _jsx("h1", {children: "Welcome"}), data.enabled ? _jsx("input", {}) : "disabled" ]}) But we'd need somethin…

Modern react developers forget that if statements exist. When react was class based it was trivial to do: render() { if (this.dontNeedToRender) { return null } } Now, because hooks can't be skipped, react developers jump through many hoops to use an if statement during rendering.

I might be missing your point, can you elaborate? If you want to write an if statement you just do it at the end of a component, after the hooks. It's a common pattern.

Re: Show HN: Aberdeen – An elegant approach to reactive UIs

#89
post #88

There are many overlaps with SolidJS. How is this project different, ignoring the obvious; that you don't support JSX.

I've tried to address the technical difference (as far as I understand Solid) at the top of this comment: https://news.ycombinator.com/item?id=43940144

Re: Show HN: Aberdeen – An elegant approach to reactive UIs

#90

Earlier quoted context omitted.

I don't particularly like how control logic needs to be embedded within JSX using ?ternary : operators and .map(() => stuff) within the HTML. Also, in order to transform JSX into individual rerunnable functions, we'd need a whole different transpiler. I like being able to code browser-runnable JavaScript directly. To each their own. :-)

re: syntax, I agree, it's stopped me from ever trying React/JSX-based frameworks, which I am sure is an over-reaction. I have a POC syntax extension (babel parser fork) I named JSXG where I introduced "generator elements" which treats the body of the element as a JS generator function that yields JSX elements. The simple/naive implementation of just running the generator was okay, but I (perhaps prematurely) worried…

That looks cool!

I think it would be pretty easy to transpile this (or something like it) to code Aberdeen can consume. In fact, it would probably be a lot easier than transpiling for React, as Aberdeen uses immediate mode the `for` problem in your comment below wouldn't be a problem at all, so no return values to worry about.

I'd use something like this myself for larger projects, I think. But asking other developers to use a different programming language just to use your library usually doesn't fly well. :-) Coming to think of it, I find it actually kind of surprising that JSX succeeded.

Post reply on HN