Skip to content

Commit d99d08d

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

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

src/action-sheet/action-sheet.ts

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

39-
ready() {
40-
this.memoInitialData();
41-
this.splitGridThemeActions();
42-
}
39+
observers = {
40+
visible(value: boolean) {
41+
if (!value) return;
42+
this.init();
43+
},
44+
45+
items() {
46+
this.init();
47+
},
48+
};
4349

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

5463
splitGridThemeActions() {
@@ -70,13 +79,6 @@ export default class ActionSheet extends SuperComponent {
7079
this._trigger('visible-change', { visible: true });
7180
},
7281

73-
memoInitialData() {
74-
this.initialData = {
75-
...this.properties,
76-
...this.data,
77-
};
78-
},
79-
8082
/** 指令调用隐藏 */
8183
close() {
8284
this.triggerEvent('close', { trigger: 'command' });
@@ -95,6 +97,13 @@ export default class ActionSheet extends SuperComponent {
9597
}
9698
},
9799

100+
onSwiperChange(e: WechatMiniprogram.TouchEvent) {
101+
const { current } = e.detail;
102+
this.setData({
103+
currentSwiperIndex: current,
104+
});
105+
},
106+
98107
onSelect(event: WechatMiniprogram.TouchEvent) {
99108
const { currentSwiperIndex, items, gridThemeItems, count, theme } = this.data;
100109
const { index } = event.currentTarget.dataset;

0 commit comments

Comments
 (0)