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 = fickle({
name : 'shadow',
hue : '#333',
ml : 200,
stats : { views : 0 },
tags : ['monochrome'] });
ink.set('name', 'smoke');
ink.set({'stats.views' : 1, 'ml' : 80});
ink.increment('stats.views', 2);
ink.decrement('stats.views', 1);
ink.get('stats')
ink.push('tags', 'special');
ink.get('tags');
ink.insert('tags', 'dark', 0);
ink.get('tags');
ink.empty('tags');
ink.get('tags');
ink.del('stats.views')
ink.get('stats');
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 = fickle({
name : 'shadow',
hue : '#333',
ml : 200,
stats : { views : 0 },
tags : ['monochrome'] });
var viewCtx = fickle.context();
serverCtx = fickle.context({
cacheTime : 5000
});
viewCtx.on(ink, 'name', function(obj, name) {
console.log("name changed to", name);
});
serverCtx.onAny(ink, function(obj, changes) {
console.log("saving fields:", changes);
});
ink.set('name', 'slate');
ink.set({name : 'silver', hue : '#777'});
ink.get("ml");
name changed to slate
name changed to silver
saving fields: {'name' : 'silver', 'hue' : '#777'}
200
viewCtx.pause(true);
viewCtx.pause(false);
viewCtx.clear(ink);
serverCtx.clearAll();