1.0.1 • Published 7 years ago

spyo v1.0.1

Weekly downloads
18
License
MIT
Repository
github
Last release
7 years ago

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

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

1.0.1

7 years ago

1.0.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago