Source: jsframework/core/internal/state.js

/**
 * Created by zhangmike on 16/10/18.
 */

export default function initState(GMP) {
    /**
     * Setup the scope of an instance, which contains:
     * - observed data
     */
    GMP._assignPros({
        _initState() {
            this._initData();
        },
        _initData() {
            this._data = this.$options.data || {};
            var keys = Object.keys(this._data);
            var that = this;
            for (var i = 0, l = keys.length; i < l; i++) {
                var key = keys[i],
                    val = this._data[keys[i]];
                var property = Object.getOwnPropertyDescriptor(this._data, key);
                if (property && property.configurable === false) {
                    continue;
                }

                (function(k, v) {
                    Object.defineProperty(that._data, k, {
                        enumerable: true,
                        configurable: true,
                        get: function reactiveGetter () {
                            return v;
                        },
                        set: function reactiveSetter (newVal) {
                            var value = v;
                            if (newVal === value) {
                                return;
                            }
                            v = newVal;
                        }
                    });
                })(key, val);
            }
        }
    });
}