Skip to content

Proxies

Damiano Di Vincenzo edited this page Apr 17, 2024 · 1 revision

LDP

LDP stands for: L-objects, D-objects, Pointers.

This system is the basis of the jodel engine, and it was born to overcome a strong limitation of redux: in redux the state cannot be directly modified, but must be edited through actions and reducers and should not have nested objects.

By accepting this limitation, jodel user-events (onDragEnd etc...) would not be able to edit the state.

Every object in jodel exists in 3 forms:

D-object

This is the serializable version which obeys Redux limitations and is rarely meant to be directly used by a jodel user but important to understand. It is the "true" representation of the object persisting in redux's state and in savefiles. each of those objects have an unique "id".

Pointers

Are the identificators of D-objects in string format, a D-object cannot change his id. They overcome the Redux limitation "should not nested objects", by storing nested objects as pointers (strings) which can be resolved at runtime.

L-objects

Are meant to overcome the Redux limitation "state cannot be directly modified"

They are Proxies wrapping the D-objects.

All the original D-object properties and values are still accessible with those extra features:

  • when trying to access a property of the D-object which is stored as a pointer, the proxy will return instead "solve" that pointer into a new proxy.

    for example, take those D-objects: var a = {id:"pointer_a", b:"pointer_b"}; var b = {id:"pointer_b", arr:["pointer_a", "pointer_c"], val:"b_val"}; var c = {id:"pointer_c", val:"C"}; After wrapping a into a proxy, accessing a.b will not return the string "pointer_b" but the object b wrapped in a proxy.

    so navigating L.wrap(a).b.val is valid and will return the string "b_val".

    Pointers can be solved also inside an array, so navigating L.wrap(b).arr[0] will return the proxy of a (same as calling L.wrap(a))

largely todo

Clone this wiki locally