+38
-22
lines changedFilter options
+38
-22
lines changed Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ import {
32
32
renderRecyclableComponentTemplate
33
33
} from 'weex/runtime/recycle-list/render-component-template'
34
34
35
-
// hooks to be invoked on component VNodes during patch
35
+
// inline hooks to be invoked on component VNodes during patch
36
36
const componentVNodeHooks = {
37
37
init (
38
38
vnode: VNodeWithData,
@@ -189,8 +189,8 @@ export function createComponent (
189
189
}
190
190
}
191
191
192
-
// merge component management hooks onto the placeholder node
193
-
mergeHooks(data)
192
+
// install component management hooks onto the placeholder node
193
+
installComponentHooks(data)
194
194
195
195
// return a placeholder vnode
196
196
const name = Ctor.options.name || tag
@@ -234,22 +234,11 @@ export function createComponentInstanceForVnode (
234
234
return new vnode.componentOptions.Ctor(options)
235
235
}
236
236
237
-
function mergeHooks (data: VNodeData) {
238
-
if (!data.hook) {
239
-
data.hook = {}
240
-
}
237
+
function installComponentHooks (data: VNodeData) {
238
+
const hooks = data.hook || (data.hook = {})
241
239
for (let i = 0; i < hooksToMerge.length; i++) {
242
240
const key = hooksToMerge[i]
243
-
const fromParent = data.hook[key]
244
-
const ours = componentVNodeHooks[key]
245
-
data.hook[key] = fromParent ? mergeHook(ours, fromParent) : ours
246
-
}
247
-
}
248
-
249
-
function mergeHook (one: Function, two: Function): Function {
250
-
return function (a, b, c, d) {
251
-
one(a, b, c, d)
252
-
two(a, b, c, d)
241
+
hooks[key] = componentVNodeHooks[key]
253
242
}
254
243
}
255
244
Original file line number Diff line number Diff line change
@@ -19,12 +19,10 @@ describe('create-component', () => {
19
19
props: ['msg'],
20
20
render () {}
21
21
}
22
-
const init = jasmine.createSpy()
23
22
const data = {
24
23
props: { msg: 'hello world' },
25
24
attrs: { id: 1 },
26
25
staticAttrs: { class: 'foo' },
27
-
hook: { init },
28
26
on: { notify: 'onNotify' }
29
27
}
30
28
const vnode = createComponent(child, data, vm, vm)
@@ -38,9 +36,6 @@ describe('create-component', () => {
38
36
expect(vnode.elm).toBeUndefined()
39
37
expect(vnode.ns).toBeUndefined()
40
38
expect(vnode.context).toEqual(vm)
41
-
42
-
vnode.data.hook.init(vnode)
43
-
expect(init.calls.argsFor(0)[0]).toBe(vnode)
44
39
})
45
40
46
41
it('create a component when resolved with async loading', done => {
Original file line number Diff line number Diff line change
@@ -374,4 +374,36 @@ describe('vdom patch: edge cases', () => {
374
374
expect(vm.$el.querySelector('custom-foo').getAttribute('selected')).toBe('1')
375
375
Vue.config.ignoredElements = []
376
376
})
377
+
378
+
// #7805
379
+
it('should not cause duplicate init when components share data object', () => {
380
+
const Base = {
381
+
render (h) {
382
+
return h('div', this.$options.name)
383
+
}
384
+
}
385
+
386
+
const Foo = {
387
+
name: 'Foo',
388
+
extends: Base
389
+
}
390
+
391
+
const Bar = {
392
+
name: 'Bar',
393
+
extends: Base
394
+
}
395
+
396
+
const vm = new Vue({
397
+
render (h) {
398
+
const data = { staticClass: 'text-red' }
399
+
400
+
return h('div', [
401
+
h(Foo, data),
402
+
h(Bar, data)
403
+
])
404
+
}
405
+
}).$mount()
406
+
407
+
expect(vm.$el.textContent).toBe('FooBar')
408
+
})
377
409
})
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