Last active
August 29, 2015 14:18
-
-
Save kaosat-dev/dbee629dcf3ae1dc39e9 to your computer and use it in GitHub Desktop.
Omniscient.js cursors getters setters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = immstruct({ something: 'initial', another: 'part' }); | |
data.on('swap', function (newData, oldData, path) { | |
console.log( | |
"new", newData.toJS(), // { something: "updated", another: 'part' } | |
"old",oldData.toJS(), // { something: "initial", another: 'part' } | |
"path",path) // ['something'] | |
}); | |
var MyData={ | |
get something(){ | |
return data.cursor('something').deref() | |
}, | |
set something( newVal ){ | |
data.cursor('something').update(function (oldValue) { | |
return newVal; | |
}); | |
}, | |
foo:3 | |
}; | |
console.log("data",MyData) | |
console.log("data",MyData.something) | |
MyData.something = 45; | |
console.log("data",MyData.something) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = immstruct({ something: 'initial', another: 'part' }); | |
data.on('swap', function (newData, oldData, path) { | |
console.log( | |
"new", newData.toJS(), // { something: "updated", another: 'part' } | |
"old",oldData.toJS(), // { something: "initial", another: 'part' } | |
"path",path) // ['something'] | |
}) | |
var proxy = new Proxy(original, { | |
get: function(target, name, receiver) { | |
var rv = target[name]; | |
if (typeof rv === "string") { | |
rv = rv.toUpperCase(); | |
} | |
return rv; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment