https://github.com/muke1908/observableobj
Observe a javascript object and react when property changes.
https://github.com/muke1908/observableobj
Last synced: about 1 year ago
JSON representation
Observe a javascript object and react when property changes.
- Host: GitHub
- URL: https://github.com/muke1908/observableobj
- Owner: muke1908
- Created: 2019-02-01T11:41:23.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-01T12:06:40.000Z (about 7 years ago)
- Last Synced: 2025-02-01T19:45:03.274Z (about 1 year ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Observable Object
Observe a javascript object and react when property changes.
## Install
`npm install reactiveobj`
## Usage
```
import Observable from 'reactiveobj';
var t = {
score:0
}
const Rt = new Observable(t)
const handler = (newVal)=>{
console.log(“I am reactive, the new value is:”, newVal)
}
Rt.observe(“score”, handler)
```
You can add multiple handler like:
```
Rt.observe(“score”, handler1)
Rt.observe(“score”, handler2)
```
## Access the observable object:
`Rt.obj`
To change value, `Rt.obj.score = 500`
NOTE: This doesn't observe nested properties