DEV Community

Discussion on: Building a Reactive Library from Scratch

Collapse
 
itamarzil123 profile image
Itamar Silverstein

Hi Ryan, Thanks for this post !

  1. Why should the Effect itself hold a list of dependencies as well. The Signal holds a list of subscriptions that should be notified whenever the signal is modified, for example setCount(5), And that does the job right ? what am I missing ? In the code above effect's dependencies are being added but not really used anywhere except for cleaning itself but why do they exist in the first place).

  2. In VueJS there is a hijacking of the state (data) itself and so at initialization the data properties are being replaced with reactive getters and setters (using defineProperty in the past and Proxy today) that notify listeners. In SolidJS is there hijacking as well ? or is it mostly 'pure functional' ?

Thanks !

Collapse
 
ryansolid profile image
Ryan Carniato

In the code above effect's dependencies are being added but not really used anywhere except for cleaning itself

  1. That is why. Each Effect needs to unsubscribe itself on cleanup/re-run. We need to know since the Signal holds the subscriptions. A long lived Signal could fire an Effect indefinitely otherwise long after it should be disposed.
  2. Solid has proxies but the prefered pattern is createStore which creates a readonly proxy and setter function combo. There is a createMutable like MobX/Vue available though.