0.0.7 • Published 6 years ago
datachange v0.0.7
DataChange
Realtime data-change watcher
CDN
https://unpkg.com/datachange
# or
https://npmcdn.com/datachange
# or
https://cdn.jsdelivr.net/npm/datachange
Usage
let obj = {
x: 0,
z: {
v: 1
},
f: [0]
}
let watcher = Change(obj, {
create() {
console.log('Watcher was created')
},
destroy() {
console.log('Watcher was destroyed')
},
change(type, prop, old, last) {
console.log('Datachange type', type, ' The property', prop, ' was changed from ', old, ' to ', last)
},
add (prop, value) {
console.log('The property', prop, ' was added and value is ', value)
},
update (prop, oldValue, value) {
console.log('The property', prop, ' was updated from ', oldValue, ' to ', value)
},
remove (prop, value) {
console.log('The property', prop, ' was removed and value was been ', value)
}
})
setTimeout(() => obj.y = 300, 1000)
setTimeout(() => {
obj.f[0] = 1;
obj.z.v = 3;
delete obj.x;
}, 2000)
setTimeout(() => {
watcher.destroy() // Destory the change watcher
}, 4000)