C callback design pattern

broken image
broken image

There's just no mechanism for doing that in vanilla JavaScript. We can't really track the reading and writing of local variables like in the example.

broken image

when A0 is assigned a new value, notify all its subscriber effects to re-run. because A0 and A1 are read when update() is being executed, update() becomes a subscriber to both A0 and A1 after the first call.ĭetect when a variable is mutated. If a variable is read when there is a currently running effect, make that effect a subscriber to that variable.

broken image

when evaluating the expression A0 + A1, both A0 and A1 are read. This whenDepsChange() function has the following tasks:

broken image