-
Notifications
You must be signed in to change notification settings - Fork 4
/
vue-nonreactive.js
43 lines (36 loc) · 1.12 KB
/
vue-nonreactive.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Disable Vue reactivity for a given object. If you're using this,
* you may want to rethink your data model. However, this plugin is
* useful in a small subset of cases where you need to prevent Vue
* from walking nested properties that do not represent application
* state. eg, your model has a reference to a data store or cache.
*
* Example:
*
* new Vue({
* el: 'body',
* data() {
* const instance = postStore.fetch({include: ['author', 'comments.author']})
* Vue.nonreactive(instance._cache)
*
* return {post: instance, },
* },
* ...
* });
*/
/* eslint-disable no-param-reassign */
function install(Vue) {
const Observer = (new Vue()).$data
.__ob__
.constructor;
Vue.nonreactive = function nonreactive(value) {
// Set dummy observer on value
value.__ob__ = new Observer({});
return value;
};
}
// auto install
/* istanbul ignore if */
if (typeof window !== 'undefined' && window.Vue)
window.Vue.use(install);
export default install;