Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/regou/overseer
overseer.js A light weight, simple Object.observe shim
https://github.com/regou/overseer
Last synced: about 1 month ago
JSON representation
overseer.js A light weight, simple Object.observe shim
- Host: GitHub
- URL: https://github.com/regou/overseer
- Owner: regou
- License: mit
- Created: 2014-01-02T06:46:25.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-06-26T14:16:11.000Z (over 10 years ago)
- Last Synced: 2024-04-25T01:41:42.507Z (8 months ago)
- Language: JavaScript
- Size: 374 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
OVERSEER
========Overseer.js A light weight, simple Object.observe shim
### Why overseer.js?
Simple : Observe JavaScript Object/Array in simple way;
Small : Only 1.54k after minified!
Use Now :
Unlike native Object.observe , Overseer support FF2.0+ Chrome1.0+ IE8+ Opera9.5+ Safari3+
### Basic usage
Overseer.watch(obj,["age"],function(change){
//Handle Change here
});### Getting Started
Include the `overseer.js` in your project.
nodejs:
npm install overseer
var Overseer=require("overseer");
### Example:
Watch obj.name and obj.age
var obj={name:"wx",age:"24",gen:"male"};
Overseer.watch(obj,["name","age"],function(change){
//Handle Change here
console.log("change ",change.key," from ",change.oldValue," to ",change.newValue);
});Then try these:
obj.name="regou"; // output: "change name from wx to regou"
obj.age="45"; // output: "change age from 24 to 45"
obj.name; //output: "regou"
obj.age; //output: 45Watch Array : Watch arr[0] and arr[1]
var arr=["Tom","Jim","Hank"];
Overseer.watch(arr,[0,1],function(change){
//Handle Change here
console.log("change ",change.key," from ",change.oldValue," to ",change.newValue);
});You can unwatch them if you want:
Overseer.unwatch(obj,["name"]); //unwatch obj.name
obj.name="pop"; // no console output,just change the value### APIs
*****
**Overseer.support**Boolean. if Browser support Overseer
*****
**Overseer.watch(Obj,keyArray,callback[,config]);**Observe one or more properties in this Object(shallow watch).
`Obj` - Object/Array. The Object/Array you want to observe;
`keyArray` - Array. The keynames/Index of the Object/Array your want to observe,must be array;
`callback` - Function. Will pass 1 object with 'key','newValue','oldValue','Obj';
`config` - Object. Do some config in this optional parameter.
`config.highPerformance` - Boolean. If you do something crazy and the value changing in very high frequency,you should set it to true(may reduce callback times).Default is false.
*******Overseer.watchAll(Obj,callback[,config]);**
Observe all properties in this Object/Array (shallow watch).
*******Overseer.unwatch(Obj,keyArray);**
Unwatch.
*******Overseer.unwatchAll(Obj);**
Unwatch All properties(shallow) in this Object/Array.Also this will restore the Obj/Array to original.