(Vue)
| 4896 | } |
| 4897 | |
| 4898 | function stateMixin (Vue) { |
| 4899 | // flow somehow has problems with directly declared definition object |
| 4900 | // when using Object.defineProperty, so we have to procedurally build up |
| 4901 | // the object here. |
| 4902 | var dataDef = {}; |
| 4903 | dataDef.get = function () { return this._data }; |
| 4904 | var propsDef = {}; |
| 4905 | propsDef.get = function () { return this._props }; |
| 4906 | { |
| 4907 | dataDef.set = function () { |
| 4908 | warn( |
| 4909 | 'Avoid replacing instance root $data. ' + |
| 4910 | 'Use nested data properties instead.', |
| 4911 | this |
| 4912 | ); |
| 4913 | }; |
| 4914 | propsDef.set = function () { |
| 4915 | warn("$props is readonly.", this); |
| 4916 | }; |
| 4917 | } |
| 4918 | Object.defineProperty(Vue.prototype, '$data', dataDef); |
| 4919 | Object.defineProperty(Vue.prototype, '$props', propsDef); |
| 4920 | |
| 4921 | Vue.prototype.$set = set; |
| 4922 | Vue.prototype.$delete = del; |
| 4923 | |
| 4924 | Vue.prototype.$watch = function ( |
| 4925 | expOrFn, |
| 4926 | cb, |
| 4927 | options |
| 4928 | ) { |
| 4929 | var vm = this; |
| 4930 | if (isPlainObject(cb)) { |
| 4931 | return createWatcher(vm, expOrFn, cb, options) |
| 4932 | } |
| 4933 | options = options || {}; |
| 4934 | options.user = true; |
| 4935 | var watcher = new Watcher(vm, expOrFn, cb, options); |
| 4936 | if (options.immediate) { |
| 4937 | try { |
| 4938 | cb.call(vm, watcher.value); |
| 4939 | } catch (error) { |
| 4940 | handleError(error, vm, ("callback for immediate watcher \"" + (watcher.expression) + "\"")); |
| 4941 | } |
| 4942 | } |
| 4943 | return function unwatchFn () { |
| 4944 | watcher.teardown(); |
| 4945 | } |
| 4946 | }; |
| 4947 | } |
| 4948 | |
| 4949 | /* */ |
| 4950 |
no test coverage detected