packages/okam-core/src/extend/data/observable/Observer.js
function makeArrayObservable(arr, observer, proxyArrApis) {
    // Here, not using __proto__ implementation, there are two import reasons:
    // First, considering __proto__ will be deprecated and is not recommended to use
    // Second, some plugins like weixin contact plugin will change array definition,
    // the array instance __proto__ property does not contains any like `push`
    // `pop` API, and these API only existed in the instance context.
    // So, like the code as the following will not work correctly,
    // a = []; // a.__proto__.push is not defined, a.push is defined
    // a.__proto__.push = function () {};
    // a.push(2); // always call the native push, not the override push method
    // Therefor, using __proto__ to proxy the array method will not work

    Object.keys(proxyArrApis).forEach(method => {
        let rawMethod = arr[method];
        arr[method] = proxyArrApis[method].bind(arr, observer, rawMethod);
    });

    arr.setItem = updateArrayItem.bind(arr, observer);
    arr.getItem = getArrayItem.bind(arr, observer);

    return arr;
}
function makeArrayObservable(arr, observer, proxyArrApis) {
    // Here, not using __proto__ implementation, there are two import reasons:
    // First, considering __proto__ will be deprecated and is not recommended to use
    // Second, some plugins like weixin contact plugin will change array definition,
    // the array instance __proto__ property does not contains any like `push`
    // `pop` API, and these API only existed in the instance context.
    // So, like the code as the following will not work correctly,
    // a = []; // a.__proto__.push is not defined, a.push is defined
    // a.__proto__.push = function () {};
    // a.push(2); // always call the native push, not the override push method
    // Therefor, using __proto__ to proxy the array method will not work

    Object.keys(proxyArrApis).forEach(method => {
        let rawMethod = arr[method];
        arr[method] = proxyArrApis[method].bind(arr, observer, rawMethod);
    });

    arr.setItem = updateArrayItem.bind(arr, observer);
    arr.getItem = getArrayItem.bind(arr, observer);

    return arr;
}
function makeArrayObservable ( arr , observer , proxyArrApis ) { // Here, not using __proto__ implementation, there are two import reasons: // First, considering __proto__ will be deprecated and is not recommended to use // Second, some plugins like weixin contact plugin will change array definition, // the array instance __proto__ property does not contains any like `push` // `pop` API, and these API only existed in the instance context. // So, like the code as the following will not work correctly, // a = []; // a.__proto__.push is not defined, a.push is defined // a.__proto__.push = function () {}; // a.push(2); // always call the native push, not the override push method // Therefor, using __proto__ to proxy the array method will not work Object . keys ( proxyArrApis ) . forEach ( method => { let rawMethod = arr [ method ] ; arr [ method ] = proxyArrApis [ method ] . bind ( arr , observer , rawMethod ) ; } ) ; arr . setItem = updateArrayItem . bind ( arr , observer ) ; arr . getItem = getArrayItem . bind ( arr , observer ) ; return arr ; }
Make array observable

@param {Array} arr the array to observe
@param {Observer} observer the observer
@param {Object} proxyArrApis the array api to proxy
@return {Array}
Make array observable