Fickle objects, with multiple observer contexts.
Fickle is intended for situations where there are multiple contexts for receiving notifications about changes, with different requirements such as time-base batch processing, different change-set formats etc.
Fickle has two very simple concepts:
Models
A model is an object with setters and getters:
var ink = ; // single value setink; // multi value setink; // increment views by 2ink; // decrement views by 1ink; // get statsink // -> { views : 2 } // push a value onto an arrayink;ink; // -> ['monochrome', 'special'] // insert a value at a given index of an arrayink;ink; // -> ['dark', 'monochrome', 'special'] // 'empty' a value: reduces a string to '', an object to {}, an array to []ink;ink; // -> [] // delete a valueink ink; // -> {}
Contexts
In Fickle, models are observed through an 'Observer Context'. Contexts determine the manner in which observers are updated, and provide methods for registering observer functions.
var ink = ; // A default context updates as soon as changes come in, this is great for// connecting to view logic.var viewCtx = fickle; // A batching context is useful when updating the server, this one updates// observers at a maximum frequency of 5 secondsserverCtx = fickle; // observe a specific key path on an object with 'on'viewCtx; // observe any changesserverCtx; // set and get some values..ink;ink;ink; // output:name changed to slatename changed to silversaving fields: 'name' : 'silver' 'hue' : '#777'200 // pausing a context stops it receiving any updatesviewCtx;viewCtx; // clearing a context unbinds observersviewCtxclearink;serverCtx;