demo/bundle.js
/**
             * Define a reactive property on an Object.
             */
Define a reactive property on an Object.
Define a reactive property on an Object .
function defineReactive (
              obj,
              key,
              val,
              customSetter,
              shallow
            ) {
              var dep = new Dep();
              var property = Object.getOwnPropertyDescriptor(obj, key);
              if (property && property.configurable === false) {
                return
              }
              var getter = property && property.get;
              if (!getter && arguments.length === 2) {
                val = obj[key];
              }
              var setter = property && property.set;
              var childOb = !shallow && observe(val);
              Object.defineProperty(obj, key, {
                enumerable: true,
                configurable: true,
                get: function reactiveGetter () {
                  var value = getter ? getter.call(obj) : val;
                  if (Dep.target) {
                    dep.depend();
                    if (childOb) {
                      childOb.dep.depend();
                      if (Array.isArray(value)) {
                        dependArray(value);
                      }
                    }
                  }
                  return value
                },
                set: function reactiveSetter (newVal) {
                  var value = getter ? getter.call(obj) : val;
                  if (newVal === value || (newVal !== newVal && value !== value)) {
                    return
                  }
                  if (process.env.NODE_ENV !== 'production' && customSetter) {
                    customSetter();
                  }
                  if (setter) {
                    setter.call(obj, newVal);
                  } else {
                    val = newVal;
                  }
                  childOb = !shallow && observe(newVal);
                  dep.notify();
                }
              });
            }
function defineReactive ( obj , key , val , customSetter , shallow ) { var dep = new Dep ( ) ; var property = Object . getOwnPropertyDescriptor ( obj , key ) ; if ( property && property . configurable === false ) { return } var getter = property && property . get ; if ( ! getter && arguments . length === 2 ) { val = obj [ key ] ; } var setter = property && property . set ; var childOb = ! shallow && observe ( val ) ; Object . defineProperty ( obj , key , { enumerable : true , configurable : true , get : function reactiveGetter ( ) { var value = getter ? getter . call ( obj ) : val ; if ( Dep . target ) { dep . depend ( ) ; if ( childOb ) { childOb . dep . depend ( ) ; if ( Array . isArray ( value ) ) { dependArray ( value ) ; } } } return value } , set : function reactiveSetter ( newVal ) { var value = getter ? getter . call ( obj ) : val ; if ( newVal === value || ( newVal !== newVal && value !== value ) ) { return } if ( process . env . NODE_ENV !== 'production' && customSetter ) { customSetter ( ) ; } if ( setter ) { setter . call ( obj , newVal ) ; } else { val = newVal ; } childOb = ! shallow && observe ( newVal ) ; dep . notify ( ) ; } } ) ; }
Define a reactive property on an Object.
Define a reactive property on an Object .
// cater for pre-defined getter/setters /* eslint-disable no-self-compare */ /* eslint-enable no-self-compare */