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

Commit

Permalink
fix: resolve memory leak issue, refactor: register event listener han…
Browse files Browse the repository at this point in the history
…dler (#37)
  • Loading branch information
jungeun-cho authored Aug 29, 2019
1 parent fd17c55 commit 71cf7bc
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@
<script>
import Calendar from 'tui-calendar';
const calendarEvents = [
'afterRenderSchedule',
'beforeCreateSchedule',
'beforeDeleteSchedule',
'beforeUpdateSchedule',
'clickDayname',
'clickSchedule',
'clickTimezonesCollapseBtn'
];
const scheduleNeedProp = [
'start',
'category'
Expand Down Expand Up @@ -161,11 +151,6 @@ export default {
this.calendarInstance.setOptions({isReadOnly: newValue});
}
},
data() {
return {
calendarInstance: null
};
},
mounted() {
this.calendarInstance = new Calendar(this.$refs.tuiCalendar, {
defaultView: this.view,
Expand All @@ -187,18 +172,18 @@ export default {
this.addEventListeners();
this.reflectSchedules();
},
destroyed() {
calendarEvents.forEach(event => this.calendarInstance.off(event));
beforeDestroy() {
this.calendarInstance.off();
this.calendarInstance.destroy();
},
methods: {
cloneData(data) {
return JSON.parse(JSON.stringify(data));
},
addEventListeners() {
calendarEvents.forEach(event => {
this.calendarInstance.on(event, (...args) => this.$emit(event, ...args));
});
for (const eventName of Object.keys(this.$listeners)) {
this.calendarInstance.on(eventName, (...args) => this.$emit(eventName, ...args));
};
},
reflectSchedules() {
if (this.schedules.length > 0) {
Expand Down

0 comments on commit 71cf7bc

Please sign in to comment.