milomg / reactively

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dumb question

mrjjwright opened this issue · comments

Everything is working wonderfully. I just have one stupid probably obvious question. Where are effects haha. I realize there is only one primitive here but how I do get them to run automatically? I guess some external mechanism is always needed? As a simple example, how to log a reactive when it changes automatically? Obviously with renders the render framework like Lit would pull values from reactives but what if you need a one off reaction?

I don't get it, if changing state doesn't trigger reactions, what does?

No big deal, just curious.

One of the design goals is to not run reactions until and unless they're needed. If you get() the value of a Reactive node or a descendant that depends on that node, and its 'dirty' because its dependencies have changed, then the reaction will run.

You probably don't want to trigger reactions on every change in the tree, that would be expensive and potentially glitchy.

Sometimes you do have a bunch of Reactive nodes (sometimes called effects),
that you want to trigger in bulk (e.g. the Reactive nodes that render to the DOM as a side effect). You can pass a second parameter to Reactive() to tag a node as an effect. Then trigger these 'effect' nodes with stabilize.

thank you!