Giter VIP home page Giter VIP logo

proxy-obverse's Introduction

#Proxy-obverse

通过ES6 Proxy实现的监测数据变化(支持多级对象或数组)

Usage

API

var observe = require(path/to/Proxy-obverse);

var arr = [
    1,
    2,
    3,
    [
        4,
        5,
        6
    ]
];


var arrOb = observe(arr, function(type, changed, oldV, newV) {

//  当被监测的值发生变化时,触发回调函数

});

arrOb.push(5);
arrOb[3].shift();

//  ...

回调参数:

参数名 意义 类型
type 对数据所做的操作 String
changed 修改的值 Array/Object/Number/String etc.
oldV 原来的值 Array
newV 修改后的值 Array
var observe = require(path/to/Proxy-obverse);

var obj = {
    name: "foo"
};


var objOb = observe(obj, function(type, prop, oldV, newV) {

//  当被监测的值发生变化时,触发回调函数

});

objOb.name = "bar";
objOb.year = 2017;

//  ...

回调参数:

参数名 意义 类型
type 对数据所做的操作 String
prop 修改的属性名 String
oldV 原来的值 Array/Object/Number/String etc.
newV 修改后的值 Array/Object/Number/String etc.

Tips

触发回调函数的条件是对数据产生直接变化的操作。当数据类型为数组时,push/pop/shift/unshift/splice或者直接修改某个下标的值这些操作,都会触发后面的回调函数;当数据类型为对象时,直接修改某个属性值或者新增一个属性值时,也会触发后面的回调函数。

proxy-obverse's People

Watchers

Seeker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.