1.0.1 • Published 1 year ago
@aarvinr/cron v1.0.1
cron
Minimal & lightweight reactive state library for JavaScript.
npm install @aarvinr/cron
Usage
cron(value)
Initializer function that sets a variable to reactive state.
import { cron } from "@aarvinr/cron";
const foo = cron("bar");
cron().get()
Returns the value of the reactive state.
foo.get(); // "bar"
cron().set()
Updates the value of reactive state and calls any listeners.
foo.set("baz");
cron().mut(method, ...args)
Calls the given method on the state with arguments and calls any listeners.
foo.mut("replace", "z", "r");
foo.get(); // "bar"
cron().mat(property)
Returns the given property of the state.
foo.mat("length"); // 3
cron().listen()
Runs callback whenever reactive state is updated.
const logger = foo.listen(() => {
console.log("change:", foo.get());
});
foo.set("qux"); // "change: qux"
cron().batch(fn)
Runs fn()
without calling listeners, and then calls listeners at end.
foo.batch(() => {
foo.set("quux");
foo.set("quuz");
}); // "change: quuz"
cron().deafen()
Stops all listeners from activating, or a specific listener.
foo.deafen(); // or logger.deafen()
foo.set("corge");