Permalink
Browse files

feat(listenonroot): Use a constant for private property name (#700)

  • Loading branch information...
tmorehouse committed Jul 16, 2017
1 parent ec5000c commit 26c8a3ecde2582bc2c6cba742971d7957d16c2b9
Showing with 14 additions and 13 deletions.
  1. +14 −13 lib/mixins/listen-on-root.js
@@ -3,6 +3,9 @@ import { isArray } from "../utils/array"
* Issue #569: collapse::toggle::state triggered too many times
* @link https://github.com/bootstrap-vue/bootstrap-vue/issues/569
*/

const BVRL = '__BV_root_listeners__';

export default {
methods: {
/**
@@ -21,13 +24,12 @@ export default {
* @chainable
*/
listenOnRoot(event, callback) {
if (!this.__bv_root_listeners || !isArray(this.__bv_root_listeners)) {
this.__bv_root_listeners = []
if (!this[BVRL] || !isArray(this[BVRL])) {
this[BVRL] = [];
}
this.__bv_root_listeners.push({ event, callback })
this.$root.$on(event, callback)

return this
this[BVRL].push({ event, callback });
this.$root.$on(event, callback);
return this;
},

/**
@@ -37,18 +39,17 @@ export default {
* @chainable
*/
emitOnRoot(event, ...args) {
this.$root.$emit(event, ...args)

return this
this.$root.$emit(event, ...args);
return this;
}
},

destroyed() {
if (this.__bv_root_listeners && isArray(this.__bv_root_listeners)) {
while (this.__bv_root_listeners.length > 0) {
if (this[BVRL] && isArray(this[BVRL])) {
while (this[BVRL].length > 0) {
// shift to process in order
const { event, callback } = this.__bv_root_listeners.shift()
this.$root.$off(event, callback)
const { event, callback } = this[BVRL].shift();
this.$root.$off(event, callback);
}
}
}

0 comments on commit 26c8a3e

Please sign in to comment.