This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit d4d61c8a7cf5edd1b32ad1e953a0817e10e34ab9
tree 08f3e31073ff1231a4f2dcb5cd8095697fb75974
parent 1d243ca2b4defbff1da4384918a770ad14288009
tree 08f3e31073ff1231a4f2dcb5cd8095697fb75974
parent 1d243ca2b4defbff1da4384918a770ad14288009
| name | age | message | |
|---|---|---|---|
| |
README | Sat Mar 21 03:53:50 -0700 2009 | |
| |
src/ | Sat Mar 21 03:42:26 -0700 2009 | |
| |
test/ | Sat Mar 21 03:42:26 -0700 2009 |
README
MUTABLE.JS
Mutable.js is a Javascript Getter/Setter Class with support for binding, locking and property watching.
SUPPORT
Mutable.js is supported by Firefox, Internet Explorer, Safari and Opera (version 10+)
USAGE
Include Mutable.js to your page
DEFINING
--------------- JAVASCRIPT --------------
var object =
{
// a variable that convert its assigned value to interger.
a: new Mutable({
value: 0,
setter: function(value)
{
this.value = parseInt(value);
}
}),
// get a and multiple it by two
b: new Mutable({
getter: function()
{
return this.parent.a() * 2;
}
})
};
-----------------------------------------
BINDING
--------------- JAVASCRIPT --------------
var a = {};
a.value = new Mutable({
value: 0,
setter: function(x)
{
this.value = x;
alert(x);
}
});
var b = {};
b.value = new Mutable({value:1});
var c = {};
c.value = new Mutable({value:10});
a.value.bind(function(){
return b.value() * c.value();
});
// Alert 10
b.value(2);
// Alert 20
c.value(20)
// Alert 40
a.value.unbind();
c.value(15);
// no alert
-----------------------------------------
LOCKING
--------------- JAVASCRIPT --------------
var a = {value: new Mutable({value:0})};
function fn1(){a.value(1);};
function fn2(){a.value(5);};
function fn3(){a.value(10);};
a.lock(fn1, fn3);
fn1() // a.value = 1
fn2() // a.value = 1
fn3() // a.value = 10
a.lock(fn2); // can't modify lock again
fn2() // a.value = 10
-----------------------------------------
LOCKING
--------------- JAVASCRIPT --------------
var a = {value: new Mutable({value:0})};
function fn(oldval, newval){
alert('a.value changed from ' + oldval + ' to ' + newval);
}
a.watch(fn);
a.value(1); // alert: a.value changed from 0 to 1
a.value(1); // no alert
a.value(10); // alert: a.value changed from 1 to 10
a.value.unwatch(fn);
a.value(12); // no alert
-----------------------------------------







