+38
-26
lines changedFilter options
+38
-26
lines changed Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
import config from '../config'
4
4
import { warn, mergeOptions } from '../util/index'
5
-
import { defineComputed } from '../instance/state'
5
+
import { defineComputed, proxy } from '../instance/state'
6
6
7
7
export function initExtend (Vue: GlobalAPI) {
8
8
/**
@@ -48,6 +48,12 @@ export function initExtend (Vue: GlobalAPI) {
48
48
)
49
49
Sub['super'] = Super
50
50
51
+
// For props and computed properties, we define the proxy getters on
52
+
// the Vue instances at extension time, on the extended prototype. This
53
+
// avoids Object.defineProperty calls for each instance created.
54
+
if (Sub.options.props) {
55
+
initProps(Sub)
56
+
}
51
57
if (Sub.options.computed) {
52
58
initComputed(Sub)
53
59
}
@@ -79,6 +85,13 @@ export function initExtend (Vue: GlobalAPI) {
79
85
}
80
86
}
81
87
88
+
function initProps (Comp) {
89
+
const props = Comp.options.props
90
+
for (const key in props) {
91
+
proxy(Comp.prototype, `_props`, key)
92
+
}
93
+
}
94
+
82
95
function initComputed (Comp) {
83
96
const computed = Comp.options.computed
84
97
for (const key in computed) {
Original file line number Diff line number Diff line change
@@ -21,6 +21,13 @@ import {
21
21
noop
22
22
} from '../util/index'
23
23
24
+
const sharedPropertyDefinition = {
25
+
enumerable: true,
26
+
configurable: true,
27
+
get: noop,
28
+
set: noop
29
+
}
30
+
24
31
export function initState (vm: Component) {
25
32
vm._watchers = []
26
33
const opts = vm.$options
@@ -71,7 +78,9 @@ function initProps (vm: Component, propsOptions: Object) {
71
78
} else {
72
79
defineReactive(props, key, value)
73
80
}
74
-
proxy(vm, props, key)
81
+
if (!(key in vm)) {
82
+
proxy(vm, `_props`, key)
83
+
}
75
84
}
76
85
observerState.shouldConvert = true
77
86
}
@@ -101,7 +110,7 @@ function initData (vm: Component) {
101
110
vm
102
111
)
103
112
} else if (!isReserved(keys[i])) {
104
-
proxy(vm, data, keys[i])
113
+
proxy(vm, `_data`, keys[i])
105
114
}
106
115
}
107
116
// observe data
@@ -128,28 +137,21 @@ function initComputed (vm: Component, computed: Object) {
128
137
}
129
138
}
130
139
131
-
const computedSharedDefinition = {
132
-
enumerable: true,
133
-
configurable: true,
134
-
get: noop,
135
-
set: noop
136
-
}
137
-
138
140
export function defineComputed (target: any, key: string, userDef: Object | Function) {
139
141
if (typeof userDef === 'function') {
140
-
computedSharedDefinition.get = createComputedGetter(key)
141
-
computedSharedDefinition.set = noop
142
+
sharedPropertyDefinition.get = createComputedGetter(key)
143
+
sharedPropertyDefinition.set = noop
142
144
} else {
143
-
computedSharedDefinition.get = userDef.get
145
+
sharedPropertyDefinition.get = userDef.get
144
146
? userDef.cache !== false
145
147
? createComputedGetter(key)
146
148
: userDef.get
147
149
: noop
148
-
computedSharedDefinition.set = userDef.set
150
+
sharedPropertyDefinition.set = userDef.set
149
151
? userDef.set
150
152
: noop
151
153
}
152
-
Object.defineProperty(target, key, computedSharedDefinition)
154
+
Object.defineProperty(target, key, sharedPropertyDefinition)
153
155
}
154
156
155
157
function createComputedGetter (key) {
@@ -249,15 +251,12 @@ export function stateMixin (Vue: Class<Component>) {
249
251
}
250
252
}
251
253
252
-
function proxy (vm: Component, source: Object, key: string) {
253
-
Object.defineProperty(vm, key, {
254
-
configurable: true,
255
-
enumerable: true,
256
-
get: function proxyGetter () {
257
-
return source[key]
258
-
},
259
-
set: function proxySetter (val) {
260
-
source[key] = val
261
-
}
262
-
})
254
+
export function proxy (target: Object, sourceKey: string, key: string) {
255
+
sharedPropertyDefinition.get = function proxyGetter () {
256
+
return this[sourceKey][key]
257
+
}
258
+
sharedPropertyDefinition.set = function proxySetter (val) {
259
+
this[sourceKey][key] = val
260
+
}
261
+
Object.defineProperty(target, key, sharedPropertyDefinition)
263
262
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4