🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

observer-data

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

observer-data

Observer data、defineProperty

latest
npmnpm
Version
1.0.4
Version published
Weekly downloads
2
-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

observer-data

Observer data、defineProperty

install

npm i observer-data --save

use

let ObserverData = require('observer-data');//cjs
//let ObserverData = require('xxx/node_modules/observer-data.umd.js');//umd
//let ObserverData = require('xxx/node_modules/observer-data.js');//cmd
//<script type="text/javascript" src="xxx/node_modules/observer-data.js"></script>//script

let observerData = new ObserverData();

observerData.data = data;
observerData.cb = function(newVal, key, oldVal){}
observerData.run();

api

  • observerData.opt.exclude
    • type:array
    • description:排除的属性,默认为空
  • observerData.opt.include
    • type:array
    • description:包涵的属性,默认所有
  • observerData.run(dep)
    • type:string
    • description:dep=='dep'那么初始化会执行一次cb
  • observerData.cb
    • type:function
    • description:每次数据改变回调
  • $set
    • type:function

    • description:为新数据绑定监听事件

    • example :

      let data = {a:1}...

      data.$set('b',2);//新绑定了一个b属性

  • $del
    • type:function

    • description:删除属性清除监听并触发回调

    • example :

      let data = {a:1,b:2}...

      data.$del('b');//解除b属性的绑定并且删除触发回调。

ps:数组经过重写,按原有方法使用也会触发监听。

Community

github npm

Keywords

observer

FAQs

Package last updated on 25 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts