Refactor to unbind on destroy

pull/256/head
cagataycivici 2020-03-16 17:25:06 +03:00
parent 0f362e78cb
commit 5996019da0
2 changed files with 27 additions and 9 deletions

View File

@ -21,8 +21,8 @@ import TerminalDoc from './TerminalDoc';
import TerminalService from '../../components/terminal/TerminalService';
export default {
mounted() {
TerminalService.$on('command', (text) => {
methods: {
commandHandler(text) {
let response;
let argsIndex = text.indexOf(' ');
let command = argsIndex !== -1 ? text.substring(0, argsIndex) : text;
@ -45,7 +45,13 @@ export default {
}
TerminalService.$emit('response', response);
});
}
},
mounted() {
TerminalService.$on('command', this.commandHandler);
},
beforeDestroy() {
TerminalService.$off('command', this.commandHandler);
},
components: {
'TerminalDoc': TerminalDoc

View File

@ -20,8 +20,8 @@ import TerminalService from 'primevue/terminalservice';
import TerminalService from 'primevue/terminalservice';
export default {
mounted() {
TerminalService.$on('command', (text) => {
methods: {
commandHandler(text) {
let response;
let argsIndex = text.indexOf(' ');
let command = argsIndex !== -1 ? text.substring(0, argsIndex) : text;
@ -44,7 +44,13 @@ export default {
}
TerminalService.$emit('response', response);
});
}
},
mounted() {
TerminalService.$on('command', this.commandHandler);
},
beforeDestroy() {
TerminalService.$off('command', this.commandHandler);
}
}
</CodeHighlight>
@ -130,8 +136,8 @@ export default {
import TerminalService from 'primevue/terminalservice';
export default {
mounted() {
TerminalService.$on('command', (text) => {
methods: {
commandHandler(text) {
let response;
let argsIndex = text.indexOf(' ');
let command = argsIndex !== -1 ? text.substring(0, argsIndex) : text;
@ -154,7 +160,13 @@ export default {
}
TerminalService.$emit('response', response);
});
}
},
mounted() {
TerminalService.$on('command', this.commandHandler);
},
beforeDestroy() {
TerminalService.$off('command', this.commandHandler);
}
}
</CodeHighlight>