0.1.0 • Published 2 years ago

observer-object v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Object watcher

Object watcher is library used to add a watercher on object. Whenever object properties being read or write get callback & set callback will be notified with the object property. This library will not make any changes on exisiting structure of the object Object read or set new values to objects are same as read

Commands

library code inside /src. examples are provided inside /src/examples.

Example 1

const ObjectWatcher = require('object-watcher').default;

const objectToWatch = {
    carName: 'Tesla',
    modelName: 'Model X'
};

function getterFunction(key, value) {
    console.log(`called getter function ${key}, ${value}`);
}

function setterFunction(key, oldValue, newValue) {
    console.log(`called setter function, key ${key}, oldValue ${oldValue}, newValue ${newValue}`);
}

const objectPropertyWatcher = new ObjectWatcher(objectToWatch, getterFunction, setterFunction);
objectPropertyWatcher.carName;
objectPropertyWatcher.modelName = 'Model Y';