Skip to content

Commit 019f0cc

Browse files
committed
feat(weex): add type declare for recycle-list hook
1 parent 30ade28 commit 019f0cc

File tree

3 files changed

+49
-29
lines changed

3 files changed

+49
-29
lines changed

flow/weex.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,17 @@ declare type WeexCompilerOptions = CompilerOptions & {
120120
declare type WeexCompiledResult = CompiledResult & {
121121
'@render'?: string;
122122
};
123+
124+
declare type WeexVirtalElement = {
125+
attrs: Object;
126+
type: string;
127+
vRef: string;
128+
}
129+
130+
declare type WeexComponentHookInstance = {
131+
virtualComponentId?: string;
132+
position: number;
133+
refs: {
134+
[string]: Array<WeexVirtalElement>
135+
}
136+
}

src/platforms/weex/runtime/components/recycle-list.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,15 @@ export default {
110110
})
111111
}
112112

113-
this._events['_attach_slot'] =
114-
instance => registerListRef(this.$parent || this, instance.position, instance.refs)
115-
this._events['_update_slot'] =
116-
instance => registerListRef(this.$parent || this, instance.position, instance.refs)
117-
this._events['_detach_slot'] =
118-
instance => registerListRef(this.$parent || this, instance.position, instance.refs, true)
113+
this._events['_attach_slot'] = (instance: WeexComponentHookInstance) => {
114+
registerListRef(this.$parent || this, instance.position, instance.refs)
115+
}
116+
this._events['_update_slot'] = (instance: WeexComponentHookInstance) => {
117+
registerListRef(this.$parent || this, instance.position, instance.refs)
118+
}
119+
this._events['_detach_slot'] = (instance: WeexComponentHookInstance) => {
120+
registerListRef(this.$parent || this, instance.position, instance.refs, true)
121+
}
119122

120123
return h('weex:recycle-list', {
121124
on: this._events

src/platforms/weex/runtime/recycle-list/virtual-component.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,27 @@ function initVirtualComponent (options: Object = {}) {
7474
initProvide(vm) // resolve provide after data/props
7575
callHook(vm, 'created')
7676

77-
registerComponentHook(componentId, 'lifecycle', 'attach', instance => {
78-
updateVirtualRef(vm, instance && instance.refs)
77+
registerComponentHook(componentId, 'lifecycle', 'attach',
78+
(instance: WeexComponentHookInstance) => {
79+
updateVirtualRef(vm, instance && instance.refs)
7980

80-
callHook(vm, 'beforeMount')
81+
callHook(vm, 'beforeMount')
8182

82-
new Watcher(
83-
vm,
84-
() => getComponentState(vm),
85-
() => vm._update(vm._vnode, false)
86-
)
83+
new Watcher(
84+
vm,
85+
() => getComponentState(vm),
86+
() => vm._update(vm._vnode, false)
87+
)
8788

88-
vm._isMounted = true
89-
callHook(vm, 'mounted')
90-
})
89+
vm._isMounted = true
90+
callHook(vm, 'mounted')
91+
})
9192

92-
registerComponentHook(componentId, 'lifecycle', 'update', instance => {
93-
updateVirtualRef(vm, instance && instance.refs)
94-
vm._update(vm._vnode, false)
95-
})
93+
registerComponentHook(componentId, 'lifecycle', 'update',
94+
(instance: WeexComponentHookInstance) => {
95+
updateVirtualRef(vm, instance && instance.refs)
96+
vm._update(vm._vnode, false)
97+
})
9698

9799
registerComponentHook(
98100
componentId,
@@ -108,15 +110,16 @@ function initVirtualComponent (options: Object = {}) {
108110
}
109111
)
110112

111-
registerComponentHook(componentId, 'lifecycle', 'detach', instance => {
112-
updateVirtualRef(vm, instance && instance.refs, true)
113-
vm.$destroy()
114-
if (vm._vmTemplate) {
113+
registerComponentHook(componentId, 'lifecycle', 'detach',
114+
(instance: WeexComponentHookInstance) => {
115+
updateVirtualRef(vm, instance && instance.refs, true)
116+
vm.$destroy()
117+
if (vm._vmTemplate) {
115118
// $flow-disable-line
116-
vm._vmTemplate.removeVirtualComponent(vm._uid)
117-
delete vm._vmTemplate
118-
}
119-
})
119+
vm._vmTemplate.removeVirtualComponent(vm._uid)
120+
delete vm._vmTemplate
121+
}
122+
})
120123
}
121124

122125
// override Vue.prototype._update

0 commit comments

Comments
 (0)