From f6e5e5acb5b8bd9daafd26956fa21bb8ea88ac00 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Tue, 3 Mar 2020 15:51:35 -0800 Subject: [PATCH] just use router methods --- addon/-private/evented.js | 38 -------------------------------------- addon/-private/notifier.js | 27 --------------------------- addon/index.js | 5 ++--- 3 files changed, 2 insertions(+), 68 deletions(-) delete mode 100644 addon/-private/evented.js delete mode 100644 addon/-private/notifier.js diff --git a/addon/-private/evented.js b/addon/-private/evented.js deleted file mode 100644 index 9acf9f0f..00000000 --- a/addon/-private/evented.js +++ /dev/null @@ -1,38 +0,0 @@ -import Notifier from './notifier'; - -// in lieue of a decorator, lets just use Mixin/composition pattern -export function addEvented(Base) { - return class extends Base { - onEvent(eventName, listener) { - return notifierForEvent(this, eventName).addListener(listener); - } - - offEvent(eventName, listener) { - return notifierForEvent(this, eventName).removeListener(listener); - } - - triggerEvent(eventName, ...args) { - const notifier = notifierForEvent(this, eventName); - if (notifier) { - notifier.trigger.apply(notifier, args); - } - } - } -} - -function notifierForEvent( - object, - eventName -) { - if (object._eventedNotifiers === undefined) { - object._eventedNotifiers = {}; - } - - let notifier = object._eventedNotifiers[eventName]; - - if (!notifier) { - notifier = object._eventedNotifiers[eventName] = new Notifier(); - } - - return notifier; -} diff --git a/addon/-private/notifier.js b/addon/-private/notifier.js deleted file mode 100644 index 02d9110c..00000000 --- a/addon/-private/notifier.js +++ /dev/null @@ -1,27 +0,0 @@ -export default class Notifier { - constructor() { - this.listeners = []; - } - - addListener(listener) { - this.listeners.push(listener); - - return () => this.removeListener(listener); - } - - removeListener(listener) { - const { listeners } = this; - - for (let i = 0, len = listeners.length; i < len; i++) { - if (listeners[i] === listener) { - listeners.splice(i, 1); - - return; - } - } - } - - trigger(...args) { - this.listeners.slice(0).forEach(listener => listener(...args)); - } -} diff --git a/addon/index.js b/addon/index.js index 2b7815c4..b052b484 100644 --- a/addon/index.js +++ b/addon/index.js @@ -1,6 +1,5 @@ import EmberRouter from '@ember/routing/router'; import { get, computed } from '@ember/object'; -import { addEvented } from './-private/evented'; import { inject } from '@ember/service'; import { getOwner } from '@ember/application'; import { scheduleOnce } from '@ember/runloop'; @@ -90,7 +89,7 @@ const CALLBACK = function(transition) { this.updateScrollPosition(transition); } -class EmberRouterScroll extends addEvented(EmberRouter) { +class EmberRouterScroll extends EmberRouter { @inject('router-scroll') service; idlePool; @@ -179,7 +178,7 @@ class EmberRouterScroll extends addEvented(EmberRouter) { } } - this.triggerEvent('didScroll'); + this.trigger('didScroll'); } _routeWillChange() {