Skip to content
This repository was archived by the owner on Jul 1, 2022. It is now read-only.

Commit 71cf7bc

Browse files
authored
fix: resolve memory leak issue, refactor: register event listener handler (#37)
1 parent fd17c55 commit 71cf7bc

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/Calendar.vue

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@
55
<script>
66
import Calendar from 'tui-calendar';
77
8-
const calendarEvents = [
9-
'afterRenderSchedule',
10-
'beforeCreateSchedule',
11-
'beforeDeleteSchedule',
12-
'beforeUpdateSchedule',
13-
'clickDayname',
14-
'clickSchedule',
15-
'clickTimezonesCollapseBtn'
16-
];
17-
188
const scheduleNeedProp = [
199
'start',
2010
'category'
@@ -161,11 +151,6 @@ export default {
161151
this.calendarInstance.setOptions({isReadOnly: newValue});
162152
}
163153
},
164-
data() {
165-
return {
166-
calendarInstance: null
167-
};
168-
},
169154
mounted() {
170155
this.calendarInstance = new Calendar(this.$refs.tuiCalendar, {
171156
defaultView: this.view,
@@ -187,18 +172,18 @@ export default {
187172
this.addEventListeners();
188173
this.reflectSchedules();
189174
},
190-
destroyed() {
191-
calendarEvents.forEach(event => this.calendarInstance.off(event));
175+
beforeDestroy() {
176+
this.calendarInstance.off();
192177
this.calendarInstance.destroy();
193178
},
194179
methods: {
195180
cloneData(data) {
196181
return JSON.parse(JSON.stringify(data));
197182
},
198183
addEventListeners() {
199-
calendarEvents.forEach(event => {
200-
this.calendarInstance.on(event, (...args) => this.$emit(event, ...args));
201-
});
184+
for (const eventName of Object.keys(this.$listeners)) {
185+
this.calendarInstance.on(eventName, (...args) => this.$emit(eventName, ...args));
186+
};
202187
},
203188
reflectSchedules() {
204189
if (this.schedules.length > 0) {

0 commit comments

Comments
 (0)