Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lc-cn/obj-observer
js/ts 对象监听
https://github.com/lc-cn/obj-observer
javascript observer proxy typescript
Last synced: 2 days ago
JSON representation
js/ts 对象监听
- Host: GitHub
- URL: https://github.com/lc-cn/obj-observer
- Owner: lc-cn
- License: mit
- Created: 2022-08-28T06:48:00.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-13T00:50:27.000Z (almost 2 years ago)
- Last Synced: 2024-10-07T14:48:34.337Z (about 1 month ago)
- Topics: javascript, observer, proxy, typescript
- Language: TypeScript
- Homepage:
- Size: 11.7 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# obj-observer
js/ts 对象监听1. 安装依赖
```shell
npm install obj-observer
# 或 npm i
```
2. 在需要的地方引入watch方法,监听对象或数组的变化
```javascript
import {ref,watch} from 'obj-observer'
const obj=ref({test:123})
const dispose=watch(obj,
(value,oldValue)=>{
console.log('trigger change',value,oldValue)
})
obj.test='hi world' //'trigger change' {test:'hello world'} {test:'hi world'}
```