Classify-Observer.js
Classify-Ovserver is a mutator for Classify.js[https://github.com/weikinhuang/Classify] that allows for simple getters and setters, and on value change events listeners for object properties.
Classify-Observer is tested in IE 6+, Firefox 2+, Safari 3+, Chrome 3+, and Opera 10+, NodeJs.
Usage
Defining a observable property
var test = ;var instance = ; // test that observers are createdinstancex instanceof ClassifyObserver; // Calling observer from object context.instancex === 10;// Calling observer from object context with defined getter.instancey === 1000;// The return value of setter function is a chain of parent instance.instancey === instance;// Calling observer from object context with setter referencing parent function.instancey === 10; // add an event listenerinstancey;// event firedinstancey; // test separate instances of instantiated classvar instance2 = ;instancex !== instance2x; //"Separate instances of classes have different observers.";
Environments
Classify is CommonJS compliant and can be used in the browser scope or the server scope.
In the browser:
<!-- Classify() is now in the global context -->
NodeJs environment:
Innpm install classifyjsnpm install classifyjs-observer
var Classify = Classify;// only needed once where classifyjs is first required;
RequireJS:
With an AMD loader like;
Building the Source
Classify-Observer uses the grunt build system. Building Classify-Observer requires node.js and a command line gzip program.
# Install grunt. $ npm install -g grunt-cli # Clone the Classify-Observer git repo. $ git clone git://github.com/weikinhuang/Classify-Observer.git$ cd Classify-Observer$ git submodule update --init # Install node modules. $ npm install # Run grunt. $ grunt
Running the tests:
$ grunt test
There are many other tasks that can be run through grunt. For a list of all tasks:
$ grunt --help
Changelog
v0.11.0
Initial split from core Classify[https://github.com/weikinhuang/Classify] mutator
About
Classify copyright 2011-2013 by Wei Kin Huang.
Build Tools: Grunt, QUnit, Benchmark.js, UglifyJS, JsHint, JsCoverage.
All code released under the MIT License.
Fork me to show support and help fix bugs!