Skip to content

Commit 4464026

Browse files
committed
refactor(action-sheet): simplify initialization logic and enhance observer functionality
1 parent 6bb91a8 commit 4464026

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/action-sheet/action-sheet.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,24 @@ export default class ActionSheet extends SuperComponent {
3636
},
3737
];
3838

39-
ready() {
40-
this.memoInitialData();
41-
this.splitGridThemeActions();
42-
}
39+
observers = {
40+
'visible, items'(visible: boolean) {
41+
if (!visible) return;
42+
this.init();
43+
},
44+
};
4345

4446
methods = {
45-
onSwiperChange(e: WechatMiniprogram.TouchEvent) {
46-
const {
47-
detail: { current },
48-
} = e;
49-
this.setData({
50-
currentSwiperIndex: current,
51-
});
47+
init() {
48+
this.memoInitialData();
49+
this.splitGridThemeActions();
50+
},
51+
52+
memoInitialData() {
53+
this.initialData = {
54+
...this.properties,
55+
...this.data,
56+
};
5257
},
5358

5459
splitGridThemeActions() {
@@ -70,13 +75,6 @@ export default class ActionSheet extends SuperComponent {
7075
this._trigger('visible-change', { visible: true });
7176
},
7277

73-
memoInitialData() {
74-
this.initialData = {
75-
...this.properties,
76-
...this.data,
77-
};
78-
},
79-
8078
/** 指令调用隐藏 */
8179
close() {
8280
this.triggerEvent('close', { trigger: 'command' });
@@ -95,6 +93,13 @@ export default class ActionSheet extends SuperComponent {
9593
}
9694
},
9795

96+
onSwiperChange(e: WechatMiniprogram.TouchEvent) {
97+
const { current } = e.detail;
98+
this.setData({
99+
currentSwiperIndex: current,
100+
});
101+
},
102+
98103
onSelect(event: WechatMiniprogram.TouchEvent) {
99104
const { currentSwiperIndex, items, gridThemeItems, count, theme } = this.data;
100105
const { index } = event.currentTarget.dataset;

0 commit comments

Comments
 (0)