It was initially created for the OH! library but has grown so much that it is now a full-blown library by itself.
Proxserve runs on both client side and server side (Node.js)
Run the following command in the terminal
Then require it:
Simplest way is to use a CDN
Don't forget to replace "1.x.x" with the desired version (recent version is 1.x.x)
If installed on your server, you may serve Proxserve on your own.
The files for distribution are located at "node_modules/proxserve/dist/".
You may choose between an unminified (proxserve.js) and minified (proxserve.min.js) versions
The heart of Proxserve is emitting events for every change made. Proxserve treats the object as a tree and emits the event up the tree.
Each event is an object emitted to whoever listens to it, holding a property of a respective path.
Let's say you have an object like this:
Altering any of the three cells of the array will emit an "update" event to "arr", to "subObj" and to "main".
Now let's say you have attached a listener to all objects and then changed the value of "main.subObj.arr" to 99.
"arr" listener will be called with a "change object" that looks like this:
"subObj" listener will be called with a similar change-object but with a path like this: ".arr"
and "main" listener will be called with a change-object with a path like this: ".subObj.arr"
Proxserve by default has its own "event loop".
It waits and accumulates changes before it fires the events in order to let you decide what data change do you want to handle and what not. This makes both, Proxserve and your own code, very efficient and fast.
The time of a cycle is controlled via the "delay" option. This cycle can be disabled.
Proxserve handles memory very efficiently but also very aggressively.
By default any sub-object that has been detached from its parent object (by delete/splice of it or its parents) will enter the "destroy" cycle.
This cycle runs once every "delay + 1000" milliseconds. This lets all scripts who might still point to the object finish their business.
Caveat: handling objects outside of the proxerve object might lead to pointing to revoked proxies (destroyed objects). This can throw unexpected errors. Consider this example:
Solutions for this situation are at the API page
Note: for those who haven't worked with proxy objects before - Proxserve object actually masks a target object. Altering the proxy object allows it to trap your handlers (set, get, etc.) and do custom operations on the target object that is behind it
Caution: after initiating a Proxserve do not refer to the original object. This will bypass Proxserve and will not emit events
There are 3 events - "create", "update" & "delete". You may listen to one of them or to all of them with the special "change" event.
Whenever you instantiate a proxserve it has "hidden" methods attached to the object and sub-objects. one of them is "on()" or the alias "$on()"
Adding event listeners to properties not yet created, Listeners adding more listeners and more.
Watch out for race conditions