π
Varwatch
Varwatch is
Built simple and made easy.
Limitations
Before continue to use, please note that this library does not support for:
- Full ES5 spec of Proxy polyfill
- Browser (for now)
- CommonJS (Built for modern EcmaScript Modules)
In short, this library only built for ESM and Node.js environment.
Installation
npm install varwatch
Usecases
Watch for data changes
import Varwatch from "varwatch";
const watch = new Varwatch();
const foo = watch.init();
watch.on("set", function (target, prop, value, receiver) {
if (prop === "try") {
console.log("Wow you try it!");
}
console.log(`Value of ${prop} changed to ${value}`);
});
foo.try = "Hello";
Watch for data retrieves
import Varwatch from "varwatch";
const watch = new Varwatch();
const foo = watch.init();
watch.on("get", function (target, prop, receiver) {
if (prop === "try") {
console.log("Wow you try it!");
}
});
foo.try = "Hello";
console.log(foo.try);
Pause watcher
import Varwatch from "varwatch";
const watch = new Varwatch();
const foo = watch.init();
watch.on("get", function () {
console.log("data retrieved");
});
watch.on("set", function () {
console.log("data changed");
});
watch.pause();
foo.try = "bar";
console.log(foo.try);
Resume watcher
import Varwatch from "varwatch";
const watch = new Varwatch();
const foo = watch.init();
watch.on("get", function () {
console.log("data retrieved");
});
watch.on("set", function () {
console.log("data changed");
});
watch.pause();
foo.try = "bar";
console.log(foo.try);
watch.resume();
foo.try = "foo";
console.log(foo.try);
Pause watcher (only one between get or set)
import Varwatch from "varwatch";
const watch = new Varwatch();
const foo = watch.init();
watch.on("get", function () {
console.log("data retrieved");
});
watch.on("set", function () {
console.log("data changed");
});
watch.pause("set");
foo.try = "bar";
console.log(foo.try);
Resume watcher (only one between get or set)
import Varwatch from "varwatch";
const watch = new Varwatch();
const foo = watch.init();
watch.on("get", function () {
console.log("data retrieved");
});
watch.on("set", function () {
console.log("data changed");
});
watch.pause("set");
foo.try = "bar";
console.log(foo.try);
watch.resume("set");
foo.try = "foo";
console.log(foo.try);
License
Varwatch is licensed under MIT License