Observable
Observable is the core of Legend State. An observable function takes any value and returns a proxied version of it
Any observable is a Node with following properties
ida unique value to identify the NodeparentIt’s a Node which is the direct parent valuechildrenit’s a Map of key with values as Nodesproxyit’s a Proxy around the Nodekeyit’s the name/type for example key can bearror the primitive value like1orhellorootThe original value along withisPrimitiveandisSafelistenersit’s a List of Listener functions
getProxy
- It accepts two arguments
- node value
- prop (optional)
Case 1: Only node value is passed
It creates a proxy on node if it’s not available.
It returns the proxy, if it’s available
Case 2: node and prop is passed
Tries to get child value from the node with prop,
Creates a proxy if not available and returns it
getChildNode
Accpets Node and key as arguments.
Modifies existing node to add children prop which is a Map, if Node already has children, it adds the key to it with value as child
getNodeValue
It Accepts a node and returns the original value from it.
set
-> set —> setProp —> updateNodes
-> set —> notify
Accessing
- Accessing any property on observable triggers
gettrap fromproxyHandler
tags: reactive-programming
sources: