ca2longoria / handlar.js

Simple MVC without the V or the C.
MIT License
1 stars 0 forks source link

handlar.js

Dropped this a while back, may pick it up, again, soon. A more complete version was made for a prior company, so this one never got the updates. Will recode.

Simple MVC without the V or the C.

Dependencies


Object Structure

Events


Examples

Object Instantiation
M = new Model();

handle = new M.Handle({
    a: 1,
    b: {
        x:'X',
        y:'Y'
    }
});
JSON Object
handle.a.$
-> 1
handle.b.$
-> {x:'X',y:'Y'}
handle.b.x.$
-> "X"

===

Event Handling
Event: change
handle.a.$on('change',function(val,old){console.log('change! '+old+' => '+val)})
handle.a = 3
-> change! 1 => 3
Event: delete

$delete() feels like it ought take an argument and delete its caller's property, rather than deleting the caller, itself. Will consider this for later.

handle.a.$on('delete',function(old){console.log('delete! '+old)})
handle.a.$delete()
-> delete! 3

// And now it looks like...
handle.$
-> {b:{x:'X',y:'Y'}}
Event removal
// Some setup
q = function(){console.log('All is transient')}
handle.b.x.$on('change',q)
handle.b.x = 'axe'
-> All is transient

// The removal
handle.b.x.$off('change',q)
handle.b.x = 'ecks'
->
Modify all
Modify some

Reference

Model

===

Handle
Handle.$

value

Handle.$on

function(eventName, func, args)

Handle.$off

function(eventName, func)

Handle.$delete

function()

Handle.\<property>...