Skip to content

Resolver Manipulation and Events

thepian edited this page Oct 4, 2014 · 6 revisions

Entries in a resolver can be change in several ways. The easiest is changing a specified point using set.

var r = Resolver({});
r.set("a.b.c","new value");

This will replace the existing value with the one you specify. If you only want to set it if it hasn't previously been set call declare. For boolean values you can also use toggle to invert the current value.

When a value changes, the previously registered change listeners will be called. The change listener signature is:

 function onchange(ev) {
 }

To add a change listener,

r.on("change","a.b.c",function(ev) {
  ev.base == r("a.b")
  ev.symbol == "b"
  ev.value == new value
  ev.oldValue == old value
  ev.binding == undefined
});

If you want the callback to be called immediately after binding add the "bind" type.

r.on("change bind","a.b.c",function(ev) {
  ev.value == new value
  binding == true/false. When binding it will be true
});

Set strategy

When you set a value you can tweak the rules for setting the nodes in the path.

     |                                                            |

---------|------------------------------------------------------------| default | overwrite undefined nodes, throw if null/blank before leaf | "force" | overwrite with object if needed to write the leaf value |

var r = Resolver({ a:null });
r.set("a.b.c","new value","force");

Clone this wiki locally