| 2864 | } |
| 2865 | |
| 2866 | function stateMixin (Vue) { |
| 2867 | // flow somehow has problems with directly declared definition object |
| 2868 | // when using Object.defineProperty, so we have to procedurally build up |
| 2869 | // the object here. |
| 2870 | var dataDef = {}; |
| 2871 | dataDef.get = function () { return this._data }; |
| 2872 | var propsDef = {}; |
| 2873 | propsDef.get = function () { return this._props }; |
| 2874 | { |
| 2875 | dataDef.set = function (newData) { |
| 2876 | warn( |
| 2877 | 'Avoid replacing instance root $data. ' + |
| 2878 | 'Use nested data properties instead.', |
| 2879 | this |
| 2880 | ); |
| 2881 | }; |
| 2882 | propsDef.set = function () { |
| 2883 | warn("$props is readonly.", this); |
| 2884 | }; |
| 2885 | } |
| 2886 | Object.defineProperty(Vue.prototype, '$data', dataDef); |
| 2887 | Object.defineProperty(Vue.prototype, '$props', propsDef); |
| 2888 | |
| 2889 | Vue.prototype.$set = set; |
| 2890 | Vue.prototype.$delete = del; |
| 2891 | |
| 2892 | Vue.prototype.$watch = function ( |
| 2893 | expOrFn, |
| 2894 | cb, |
| 2895 | options |
| 2896 | ) { |
| 2897 | var vm = this; |
| 2898 | options = options || {}; |
| 2899 | options.user = true; |
| 2900 | var watcher = new Watcher(vm, expOrFn, cb, options); |
| 2901 | if (options.immediate) { |
| 2902 | cb.call(vm, watcher.value); |
| 2903 | } |
| 2904 | return function unwatchFn () { |
| 2905 | watcher.teardown(); |
| 2906 | } |
| 2907 | }; |
| 2908 | } |
| 2909 | |
| 2910 | /* */ |
| 2911 | |