src/mixins/listen-on-root.js
/**
     * Safely register a $once event listener on the root Vue node.
     * While Vue automatically removes listeners for individual components,
     * when a component registers a listener on root and is destroyed,
     * this orphans a callback because the node is gone,
     * but the root does not clear the callback.
     *
     * When registering a $root listener, it also registers a listener on
     * the component's `beforeDestroy` hook to automatically remove the
     * event listener from the $root instance.
     *
     * @param {string} event
     * @param {function} callback
     * @chainable
     */
Safely register a $once event listener on the root Vue node.
While Vue automatically removes listeners for individual components,
when a component registers a listener on root and is destroyed,
this orphans a callback because the node is gone,
but the root does not clear the callback.

When registering a $root listener, it also registers a listener on
the component's `beforeDestroy` hook to automatically remove the
event listener from the $root instance.

@param {string} event
@param {function} callback
@chainable
Safely register a $once event listener on the root Vue node . While Vue automatically removes listeners for individual components when a component registers a listener on root and is destroyed this orphans a callback because the node is gone but the root does not clear the callback . When registering a $root listener it also registers a listener on the component ' s ` beforeDestroy ` hook to automatically remove the event listener from the $root instance . @param { string } event @param { function } callback @chainable
listenOnRootOnce(event, callback) {
      this.$root.$once(event, callback)
      this.$on('hook:beforeDestroy', () => {
        this.$root.$off(event, callback)
      })
      return this
    }
listenOnRootOnce ( event , callback ) { this . $root . $once ( event , callback ) this . $on ( 'hook:beforeDestroy' , ( ) => { this . $root . $off ( event , callback ) } ) return this }
Safely register a $once event listener on the root Vue node.
Safely register a $once event listener on the root Vue node .
// Return this for easy chaining