observer-tiny
v1.0.0
Published
```typescript declare function observer<T>(data: T, getter: (target: object, key: any) => void, setter: (target: object, k: any, val: any, oldVal: any) => void): T; ```
Downloads
3
Readme
响应式数据
declare function observer<T>(data: T, getter: (target: object, key: any) => void, setter: (target: object, k: any, val: any, oldVal: any) => void): T;
example
const proxtData = observer({
a: 3,
b: [1,2,3]
}, () => {}, (t,k,v,o) => {
console.log('setter: ', t, k, v, o)
})
proxtData.a = 4
proxtData.b[0] = 4
// output:
// setter: { a: 4, b: [ 1, 2, 3 ] } a 4 3
// setter: [ 4, 2, 3 ] 0 4 1