ob-def
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

介绍

可以监听到一个对象属性值发生变化

安装

# 通过 npm 或 yarn 或 pnpm 安装

# npm
npm i ob-def

# yarn
yarn add ob-def

# pnpm
pnpm add ob-def

使用

import { observer, watch } from 'ob-def'

const obj = observer({a:1})

// watch的第三个参数详见下方WatcherOptions
watch(() => obj.a, (newVal, oldVal) => {
  console.log(newVal, oldVal)
})

// 当obj.a 发生变化时,会触发watch的回调
obj.a = 2

WatcherOptions

属性名 描述 类型 默认值
sync 是否同步监听 boolean false
deep 是否深度监听 boolean false

Package Sidebar

Install

npm i ob-def

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

4.07 kB

Total Files

4

Last publish

Collaborators

  • dylan66ty