https://github.com/screamz/observable-state-proxy
An embedded JavaScript State observable library with minimal footprint.
https://github.com/screamz/observable-state-proxy
Last synced: about 1 year ago
JSON representation
An embedded JavaScript State observable library with minimal footprint.
- Host: GitHub
- URL: https://github.com/screamz/observable-state-proxy
- Owner: ScreamZ
- Created: 2024-11-17T23:18:07.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-18T11:41:56.000Z (over 1 year ago)
- Last Synced: 2025-02-08T00:42:32.709Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 37.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Embedded : Observable state proxy
> [!IMPORTANT]
> This module is ESM only.
This module provides a proxy that can be used to observe changes to an object's properties. It's optimized for use with embedded systems, where memory is limited and performance is critical.
## Installation
```sh
npm install @embedded-js/observable-state-proxy
```
## Example usage
```ts
import {
createObservableProxy,
subscribeKey,
} from "@embedded-js/observable-state-proxy";
const stateObs = createObservableProxy({
count: 0,
name: "example",
});
const unsubscribe = subscribeKey(stateObs, "count", (newValue) => {
console.log(`count changed to ${newValue}`);
});
stateObs.count = 1; // Console: count changed from 0 to 1
stateObs.name = "test"; // No console output
unsubscribe();
stateObs.count = 2; // No console output
```