
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
observer-hooks
Advanced tools
Observable Module This is a lightweight and reusable Observable module inspired by React hooks. It provides a simple way to observe changes to an object's properties and subscribe to those changes using callback functions.
Installations
To use this module, simply import the useObservable function from the observable-hooks file:
import useObservable from "observable-hooks";
Usage
const person = { name: "John", age: 30 };
const observable = useObservable(person);
const unsubscribe = observable.subscribe((prop, value) => {
console.log(`${prop} changed to ${value}`);
});
observable.set("age", 31); // Output: "age changed to 31"
observable.set("name", "Jane"); // Output: "name changed to Jane"
unsubscribe();
API
useObservable(obj)
obj (Object): The object to be observed.
Returns an object with the following methods:
subscribe(callback)
callback (Function): The function to be called when a property changes. It receives two arguments: prop (the property name) and value (the new value).
unsubscribe(callback)
callback (Function): The function to be unsubscribed from property changes.
set(prop, value)
prop (string): The property name to update.
value (any): The new value for the property.
get(prop)
prop (string): The property name to retrieve.
Returns the current value of the property.
import useObservable from "observable-hooks";
const person = { name: "John", age: 30 };
const observable = useObservable(person);
const unsubscribe = observable.subscribe((prop, value) => {
console.log(`${prop} changed to ${value}`);
});
observable.set("age", 31); // Output: "age changed to 31"
observable.set("name", "Jane"); // Output: "name changed to Jane"
unsubscribe();
observable.set("age", 32); // No output
import useObservable from "observable-hooks";
const person = { name: "John", age: 30, address: { city: "New York" } };
const observable = useObservable(person);
const unsubscribe = observable.subscribe((path, value) => {
console.log(`${path} changed to ${value}`);
});
observable.set("age", 31); // Output: "age changed to 31"
observable.set("address.city", "San Francisco"); // Output: "address.city changed to San Francisco"
observable.set(["address", "zipCode"], "94101"); // Output: "address.zipCode changed to 94101"
unsubscribe();
FAQs
Light weight Obervables hooks
We found that observer-hooks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.