Spyo
Observe an object, check when it's change.
Installation
Node.js
npm install spyo --save
Browser
Local
CDN unpkg
Example
const Spyo = ; const myObject = firstName: 'Mike' lastName: 'Red'; const mySpy = myObject; myObjectfirstName = 'John'; mySpy;
Use provider function
const mySpy = { return Math;}; mySpy;
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
- .isEqual(a, b, exclude) ⇒
new Spyo(obj, [opts])
Create instance
Param | Type | Default | Description |
---|---|---|---|
obj | Object | function | object that you want watch |
|
[opts] | Object | configuration object |
|
[opts.autoWatch] | boolean | true | auto watch |
[opts.checkMs] | number | 50 | interval in milliseconds for every check |
[opts.provider] | function |
| optional function called on every check that returns new state |
[opts.exclude] | String | Array |
| exclude a property or more from check |
[opts.autoReset] | boolean | false | reset changes detected after check |
spyo.refresh(obj)
Refresh data source object
Kind: instance method of Spyo
Param |
---|
obj |
Spyo
spyo.check() ⇒ Check if it's different and call onChange
callback
Kind: instance method of Spyo
Spyo
spyo.watch() ⇒ Start watching
Kind: instance method of Spyo
Spyo
spyo.unwatch([reset]) ⇒ Stop watching
Kind: instance method of Spyo
Param | Type | Description |
---|---|---|
[reset] | boolean | reset changes detected |
boolean
spyo.isWatching() ⇒ Detect if check is active
Kind: instance method of Spyo
Spyo
spyo.onChange(callback) ⇒ Fired when object is isChanged
Kind: instance method of Spyo
Param |
---|
callback |
boolean
spyo.isChanged() ⇒ Check if object is changed
Kind: instance method of Spyo
Spyo
spyo.reset() ⇒ Reset changes detected
Kind: instance method of Spyo
boolean
Spyo.isEqual(a, b, exclude) ⇒ Check if two object are equals (deep check)
Kind: static method of Spyo
Param | Type | Description |
---|---|---|
a | object | first object |
b | object | second object |
exclude | Array | exclude properties from check |
boolean
Spyo.isIterable(obj) ⇒ Check if is an array or an plain object
Kind: static method of Spyo
Param |
---|
obj |
boolean
Spyo.isObject(obj) ⇒ Check for plain object
Kind: static method of Spyo
Param | Type |
---|---|
obj | * |
boolean
Spyo.isArray(obj) ⇒ Check for array
Kind: static method of Spyo
Param | Type |
---|---|
obj | * |
Changelog
You can view the changelog here
License
Spyo is open-sourced software licensed under the MIT license