Reactive programming
Reactive programming creates an internal mechanism that automatically updates things when a special kind of object* is changed. No need to call functions or subroutines do do that. You change object A, and B is automatically changed too.
* I understand only objects can be reactors(?).
Reactor: is the object that, when changed, triggers the changes in other objects. Created by make reactor!
.
Reactive expression: changes when the reactor changes. Created by is
.
make reactor! & is
This is the most simple program I could think of using reactive programming:
?house
house
?fly
fly
?bee
bee
A reactor can update itself:
?33
35
?45
47
Be careful not create an endless loop: If a change triggers a change in itself.
deep-reactor!
Just like copy
has the refinement /deep
to reach nested values (blocks within the main block), so does reactor!
.
This program is supposed to repeat what you type on the console, but it does not work:
?house
no change
?blue
no change
However, if you change to deep-reactor!
:
?house
house
?blue
blue
react
This is a command used for creating reactive GUIs. Please look at GUI- Advanced topics.
Cut-and-pasted from the documentation:
clear-reactions
Removes all defined reactions, unconditionally.
react?
Checks if an object’s field is a reactive source . If it is, the first reaction found where that object’s field is present as a source, will be returned, otherwise none
is returned./target
refinement checks if the field is a target instead of a source, and will return the first reaction found targeting that field or none
if none matches.
dump-reactions
Outputs a list of registered reactions for debug purposes.