From 277080fb1c3bfb31a0f3498ea280fa7611112686 Mon Sep 17 00:00:00 2001 From: Jiayu Liu Date: Sat, 25 Aug 2018 22:02:30 +0800 Subject: [PATCH] update component relationship api calls --- types/weixin-app/index.d.ts | 12 ++++++------ types/weixin-app/weixin-app-tests.ts | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/types/weixin-app/index.d.ts b/types/weixin-app/index.d.ts index a5e8abe504..6c8e44b484 100644 --- a/types/weixin-app/index.d.ts +++ b/types/weixin-app/index.d.ts @@ -3352,17 +3352,17 @@ type ThisTypedComponentOptionsWithRecordProps< > & ThisType>>; -interface ComponentRelation { +interface ComponentRelation { /** 目标组件的相对关系,可选的值为 parent 、 child 、 ancestor 、 descendant */ - type: string; + type: "parent" | "child" | "ancestor" | "descendant"; /** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */ target?: string; /** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */ - linked?: (...args: any[]) => void; + linked?: (target: Component) => void; /** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */ - linkChanged?: (...args: any[]) => void; + linkChanged?: (target: Component) => void; /** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */ - unlinked?: (...args: any[]) => void; + unlinked?: (target: Component) => void; } /** * Component组件参数 @@ -3505,7 +3505,7 @@ interface Component { /** * 获取所有这个关系对应的所有关联节点,参见 [组件间关系](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/custom-component/relations.html) */ - getRelationNodes(relationKey: string): { [key: string]: ComponentRelation }; + getRelationNodes(relationKey: string): ComponentRelation[]; } declare function Component( options?: ThisTypedComponentOptionsWithRecordProps, D, M, O, P> diff --git a/types/weixin-app/weixin-app-tests.ts b/types/weixin-app/weixin-app-tests.ts index adbd641b3e..c805c2c5bf 100644 --- a/types/weixin-app/weixin-app-tests.ts +++ b/types/weixin-app/weixin-app-tests.ts @@ -65,12 +65,15 @@ Component({ type: "parent", // 关联的目标节点应为父节点 linked(target) { // 每次被插入到custom-ul时执行,target是custom-ul节点实例对象,触发在attached生命周期之后 + target.data; }, linkChanged(target) { // 每次被移动后执行,target是custom-ul节点实例对象,触发在moved生命周期之后 + target.data; }, unlinked(target) { // 每次被移除时执行,target是custom-ul节点实例对象,触发在detached生命周期之后 + target.data; } } }