spyo
v1.0.1
Published
Observe object
Downloads
11
Readme
Spyo
Observe an object, check when it's change.
Installation
Node.js
npm install spyo --save
Browser
Local
<script src="node_modules/spyo/dist/spyo.min.js"></script>
CDN unpkg
<script src="https://unpkg.com/spyo/dist/spyo.min.js"></script>
Example
const Spyo = require('spyo');
const myObject = {
firstName: 'Mike',
lastName: 'Red'
};
const mySpy = new Spyo(myObject);
myObject.firstName = 'John';
mySpy.onChange((different) => {
console.log('is different:', different);
});
Use provider function
const mySpy = new Spyo(() => {
return Math.random();
});
mySpy.onChange((different) => {
console.log('is different:', different);
});
API
Spyo
Kind: global class
- Spyo
- new Spyo(obj, [opts])
- instance
- .refresh(obj)
- .check() ⇒ Spyo
- .watch() ⇒ Spyo
- .unwatch([reset]) ⇒ Spyo
- .isWatching() ⇒ boolean
- .onChange(callback) ⇒ Spyo
- .isChanged() ⇒ boolean
- .reset() ⇒ Spyo
- static
- .isEqual(a, b, exclude) ⇒ boolean
- .isIterable(obj) ⇒ boolean
- .isObject(obj) ⇒ boolean
- .isArray(obj) ⇒ boolean
new Spyo(obj, [opts])
Create instance
spyo.refresh(obj)
Refresh data source object
Kind: instance method of Spyo
spyo.check() ⇒ Spyo
Check if it's different and call onChange
callback
Kind: instance method of Spyo
spyo.watch() ⇒ Spyo
Start watching
Kind: instance method of Spyo
spyo.unwatch([reset]) ⇒ Spyo
Stop watching
Kind: instance method of Spyo
spyo.isWatching() ⇒ boolean
Detect if check is active
Kind: instance method of Spyo
spyo.onChange(callback) ⇒ Spyo
Fired when object is isChanged
Kind: instance method of Spyo
spyo.isChanged() ⇒ boolean
Check if object is changed
Kind: instance method of Spyo
spyo.reset() ⇒ Spyo
Reset changes detected
Kind: instance method of Spyo
Spyo.isEqual(a, b, exclude) ⇒ boolean
Check if two object are equals (deep check)
Kind: static method of Spyo
Spyo.isIterable(obj) ⇒ boolean
Check if is an array or an plain object
Kind: static method of Spyo
Spyo.isObject(obj) ⇒ boolean
Check for plain object
Kind: static method of Spyo
Spyo.isArray(obj) ⇒ boolean
Check for array
Kind: static method of Spyo
Changelog
You can view the changelog here
License
Spyo is open-sourced software licensed under the MIT license
Author
Fabio Ricali