Live data from Hacker News

What Are Signals?

signia.tldraw.dev

31–40 of 63 posts

Re: What Are Signals?

#31
Remember when signals - aka the observer pattern - were a stupid overengineered enterprise design pattern object oriented programmers had to use because they were too dumb to understand functional programming?

Now they're back, baby. Happy to see them used again, even if we've had to razzle it up a bit with a new name.

Re: What Are Signals?

#32
post #5

Earlier quoted context omitted.

Same here, I have been spreading mobx everywhere I have gone. There's usually some resistance but once people got used to automatic dependency tracking, they never go back. I've seen so many projects get bogged down in props hell, then gobs of context api and performance problems when too many things react at once. Mobx has been solving these problems for a long time now!

I recently started ripping Mobx out of my app. Mobx solved exactly 1 problem for me, which was passing data horizontally (to siblings/cousins) and even to non-React components. But now `useSyncExternalStore` solves that. No context needed. Can read and write state anywhere, even outside components. No "observe" or "track" shenanigans. Efficient updates (can listen to a subsection of the tree).

That appears to be in beta still? What store are you using with it?

I'll keep an eye on it! But mobx does more than that, like a lot of component optimizations and utilities. It's been so good for so long, I'm not in a rush to get rid of it.

Re: What Are Signals?

#33
post #32

Earlier quoted context omitted.

I recently started ripping Mobx out of my app. Mobx solved exactly 1 problem for me, which was passing data horizontally (to siblings/cousins) and even to non-React components. But now `useSyncExternalStore` solves that. No context needed. Can read and write state anywhere, even outside components. No "observe" or "track" shenanigans. Efficient updates (can listen to a subsection of the tree).

That appears to be in beta still? What store are you using with it? I'll keep an eye on it! But mobx does more than that, like a lot of component optimizations and utilities. It's been so good for so long, I'm not in a rush to get rid of it.

`useSyncExternalStore` was shipped live in React 18.0 and is fully ready for production use.

Source: I'm the primary Redux maintainer, and worked with Andrew Clark of the React team to nail down the semantics and behavior needed by `useSyncExternalStore` in practice. They had the idea, but discussed a lot of the necessary use cases with us and other lib maintainers, and a lot of its internal implementation is directly related to how React-Redux's `useSelector` hook was implemented already.

I built the first working code that used it by prototyping React-Redux v8's switch from our own internal subscription handling to `useSyncExternalStore` instead and gave Andrew feedback:

- https://github.com/reduxjs/react-redux/pull/1808

Re: What Are Signals?

#34

Earlier quoted context omitted.

Because it's nicer. The mental model of reading the functions using signals is; it's all about initialize|constructor|new function. And then those off-jsx stuff starts to make sense since you won't re-initialize those things. They need to exist somewhere in particular execution model. In Solidjs, it's effects (compiled from jsx where signals are read). I think those who are familiar with static type languages, natura…

When you have a big app, it becomes a spaghetti mess, and I speak from personal experience having to untangle that spaghetti.

What approach do you prefer for big apps?

The state has to go somewhere, curious how you choose to handle it.

Re: What Are Signals?

#35

Earlier quoted context omitted.

When you have a big app, it becomes a spaghetti mess, and I speak from personal experience having to untangle that spaghetti.

What approach do you prefer for big apps? The state has to go somewhere, curious how you choose to handle it.

Personally I just use Redux Toolkit with RTK Query for any synchronization with backend state. What I like about Redux is that it takes the immutable functional approach, you cannot change previous state but must instead derive new state from the old state very explicitly. In this way, it's the antithesis of signal-based state.

Re: What Are Signals?

#37

I don't really understand why people like signals again. I used a signals-like reactive programming model in VueJS a while ago and hated that you could never be sure exactly where things were being changed. Thankfully it seems that the React creators and maintainers are not hopping on the signals train and are instead adamant about unidirectional dataflow with explicit mapping of state to UI, which, as has been the r…

That sounds like a limitation of solid. In Vue, you can use return type to differentiate if you are in ts atleast

Re: What Are Signals?

#38

I don't really understand why people like signals again. I used a signals-like reactive programming model in VueJS a while ago and hated that you could never be sure exactly where things were being changed. Thankfully it seems that the React creators and maintainers are not hopping on the signals train and are instead adamant about unidirectional dataflow with explicit mapping of state to UI, which, as has been the r…

That example makes a lot of sense once you realize how JSX works in SolidJS (and its very different from React):

1. The function is called only once at component construction, and never again. Unlike React, it is _not_ called for every render.

2. Every expression in `{}` is compiled to a thunk function - not to a direct JS expression.

For example, the expression

   {props.count * 2}
compiles to

    memo(() => props.count * 2)

Another interesting bit - as the article above rightfully points out, `useState` and `useMemo` are signals. The main difference is that you have to track and specify your dependencies manually, whereas Solid auto-tracks dependencies based on their usage while the computation runs.

Re: What Are Signals?

#39

Earlier quoted context omitted.

Because it's nicer. The mental model of reading the functions using signals is; it's all about initialize|constructor|new function. And then those off-jsx stuff starts to make sense since you won't re-initialize those things. They need to exist somewhere in particular execution model. In Solidjs, it's effects (compiled from jsx where signals are read). I think those who are familiar with static type languages, natura…

When you have a big app, it becomes a spaghetti mess, and I speak from personal experience having to untangle that spaghetti.

Counterpoint: I've worked on a big application that used MobX and had no such issues.

Re: What Are Signals?

#40

I don't really understand why people like signals again. I used a signals-like reactive programming model in VueJS a while ago and hated that you could never be sure exactly where things were being changed. Thankfully it seems that the React creators and maintainers are not hopping on the signals train and are instead adamant about unidirectional dataflow with explicit mapping of state to UI, which, as has been the r…

here’s a debunking of the third tweet with reference: https://twitter.com/antonycourtney/status/162970259437243597...
Post reply on HN