TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What Are Signals?

91 pointsby sanketpatrikarabout 2 years ago

11 comments

satvikpendemabout 2 years ago
I don&#x27;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 reason for why React had been invented in the first place, makes reasoning about the application much easier [0][1].<p>This is a good thread about their drawbacks [2]. Apparently, both the below examples actually do different things:<p><pre><code> function One(props) { const doubleCount = props.count * 2; return &lt;div&gt;Count: {doubleCount}&lt;&#x2F;div&gt; } function Two(props) { return &lt;div&gt;Count: {props.count * 2}&lt;&#x2F;div&gt; } </code></pre> Like the tweeter says, signals are mutable state. I&#x27;ll stick with unidirectional data flow in React.<p>[0] <a href="https:&#x2F;&#x2F;twitter.com&#x2F;jordwalke&#x2F;status&#x2F;1629663133039214593" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;jordwalke&#x2F;status&#x2F;1629663133039214593</a><p>[1] <a href="https:&#x2F;&#x2F;twitter.com&#x2F;dan_abramov&#x2F;status&#x2F;1629539600489119744" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;dan_abramov&#x2F;status&#x2F;1629539600489119744</a><p>[2] <a href="https:&#x2F;&#x2F;twitter.com&#x2F;devongovett&#x2F;status&#x2F;1629540226589663233" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;devongovett&#x2F;status&#x2F;1629540226589663233</a>
评论 #35026410 未加载
评论 #35024657 未加载
评论 #35027225 未加载
评论 #35024821 未加载
评论 #35024366 未加载
评论 #35024301 未加载
评论 #35024120 未加载
评论 #35026669 未加载
评论 #35027957 未加载
评论 #35024293 未加载
评论 #35026397 未加载
评论 #35026450 未加载
评论 #35028073 未加载
评论 #35024239 未加载
dupedabout 2 years ago
At first I thought this was talking about Unix signals<p>Then I thought for a moment it was talking about a &quot;signal&quot; in the information theoretical sense<p>All I came away with was that they&#x27;ve invented a new name for event driven architectures and&#x2F;or data flow programming.<p>I know naming is hard but we need to stop overloading terms.
评论 #35024978 未加载
评论 #35023963 未加载
评论 #35024733 未加载
评论 #35026932 未加载
评论 #35024275 未加载
评论 #35024886 未加载
评论 #35023949 未加载
dustingetzabout 2 years ago
signals represent continuous time varying quantities, like an electrical voltage, an audio signal or the current mouse coordinates. streams (event streams) represent a sequence of discrete events, like key presses or network packets or financial transactions.<p>the key difference is in backpressure strategy: signals are canonically lazy, they don’t compute or do work until sampled, and only the latest value is relevant (nobody cares where the mouse was a moment ago when nobody was looking). streams are eager, you can’t skip a keyboard event or a financial transaction, even if the pipes are backed up – instead you have to tell upstream to slow down so you can catch up. The benefit of event streams is the guarantee that you&#x27;ll see every event, which means streams are suitable for driving sequences of side effects (keyboard event -&gt; network request -&gt; database transaction).<p>signals are a good fit for rendering because you only want to render at up to say 60fps (even if the mouse updates faster, which it does). and you only want to render what’s onscreen, and only when the tab is focused. rendering (say dom effects) is indeed effectful but not in the discrete way; the dom is a resource, it has a mount&#x2F;unmount object lifecycle, and due to this symmetry it is a good fit for rendering whereas isolated effects (without a corresponding undo operation) are a terrible fit for signals because backpressure will drop events and corrupt the system state.<p>You can use streams for rendering too, but it&#x27;s dis-optimal, and potentially by a <i>lot</i>. If your app chokes on a burst of events, you want to skip ahead and render the final state without bothering to render all the intermediate historical states. Signal laziness is what enables this &quot;work skipping&quot;; a stream would have to process each individual event in sequence.<p>I have no idea if JS projects get the backpressure right, can anyone confirm?
jitlabout 2 years ago
It’s kinda funny to see “signals” coming round into fashion or popular discussion in front-end tech Twitter. Mobx is a signals state management library has been around for 7 years. Notion used signals internally for state management and often when engineers joined they’d ask why we use signals over Redux, can we switch to Redux because it’s more modern, etc. Now it’s 4 years later and for some reason this pattern is all the rage. I’m glad I didn’t waste time on Redux just in time for trends to move on.<p>To discuss more specifically TLDraw’s Signia library, I think the ability to do manual diff tracking &amp; incremental updates for computed stores is an interesting “escape hatch”. Docs here: <a href="https:&#x2F;&#x2F;signia.tldraw.dev&#x2F;docs&#x2F;incremental" rel="nofollow">https:&#x2F;&#x2F;signia.tldraw.dev&#x2F;docs&#x2F;incremental</a><p>Most signal libraries I’ve seen try to lean hard into magic auto-tracking of dependencies which means they make it really easy for the developer to correctly observe a lot of dependencies, cool on correctness, but then have a very limited set of tools to deal with the performance implication of some computation needing to re-run a whole bunch. The differential tracking here means that if you see such a hotspot, you can get really manual optimization of recomputation without needing to squeeze into the libraries pre-packaged observable collection API.<p>Downside of this API is it seems quite easy to get it wrong.<p>Another thing I like about Signia is the use of logical time. I saw this first in Jotai internals, then in Starbeam. I haven’t dug into the source of the library yet but I think logical time is a good approach and makes inspecting internals make a bit more sense than inspecting systems (like Notion’s) that rely purely on update notification listeners.
评论 #35025903 未加载
评论 #35023925 未加载
评论 #35024896 未加载
bedersabout 2 years ago
Building &#x27;signal graphs&#x27; because views subscribe to err signals is an old hat for re-frame users who are benefiting from a clean and simple mechanism to react to data changes since forever.<p>Subscriptions grow from the leaf up to the root (which is a single app &quot;db&quot;) and so computation is minimal. If something writes to the &quot;db&quot;, only relevant subscriptions are recomputed and only views subscribing to those are &quot;repainted&quot;.<p>Works like magic.
c-smileabout 2 years ago
Hmmm... attempt to define signals using ReactJS&#x27; useState()&#x2F;useMemo() vocabulary appears as really bad idea.<p>PReact&#x27;s signal() as a concept is better - more pure. <a href="https:&#x2F;&#x2F;preactjs.com&#x2F;guide&#x2F;v10&#x2F;signals&#x2F;" rel="nofollow">https:&#x2F;&#x2F;preactjs.com&#x2F;guide&#x2F;v10&#x2F;signals&#x2F;</a>
syngrog66about 2 years ago
I did some intense Linux&#x2F;POSIX signals work in C over the last year, and expected this article to be about those creatures, since so foundational.<p>Nope.
exclipyabout 2 years ago
Why does Signia exist when there&#x27;s mobx?
picturabout 2 years ago
This does not differ from the logic that comes with React hooks. &quot;We&#x27;ve added new magic for you. Everything is done in the background. You just code the way we want.&quot;. This logic generally results in new complexities eventually. Because I don&#x27;t think there&#x27;s any benefit in trying to hide the obvious complexity in this way.
revskillabout 2 years ago
Signal is a comonad in the category of endofunctors, what&#x27;s the problem ?
LAC-Techabout 2 years ago
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?<p>Now they&#x27;re back, baby. Happy to see them used again, even if we&#x27;ve had to razzle it up a bit with a new name.