0.1.5 • Published 3 years ago
@titodp/write-effect v0.1.5
Write Effect
It tracks changes, and deep changes on an object. Runs a callback whenever something changes.
Usage
import writeEffect from '@titodp/write-effect'
let state = writeEffect({}, (target, prop, value) => {
console.log(
'Effect found!, changed prop "' + prop + '" with value "',
value,
'" on the object:',
target,
)
})
state.size = 20
setTimeout(() => {
state.size = 49
setTimeout(() => {
state.bla = {
something: {
well: 'test',
},
}
setTimeout(() => {
state.bla.something.well = 'yeah'
}, 2000)
}, 2000)
}, 2000)
Install
npm install @titodp/write-effect
How it works?
It uses a recursive set
proxy trap. Keeps track of parent objects and iterates them to run the callbacks.
Author
URL
0.1.5
3 years ago