DEV: Remove EventTarget. Future versions of Ember don't export this.

It was removed altogether from ApplicationRoute, which only triggered
an `activate` event which never seems to be used.

We can replace it with Evented which is still present.
This commit is contained in:
Robin Ward 2020-04-20 16:18:17 -04:00
parent afe1407c75
commit 96d026a329
5 changed files with 25 additions and 24 deletions

View File

@ -108,7 +108,6 @@ var define, requirejs;
},
rsvp: {
default: Ember.RSVP,
EventTarget: Ember.RSVP.EventTarget,
Promise: Ember.RSVP.Promise,
hash: Ember.RSVP.hash,
all: Ember.RSVP.all

View File

@ -1,5 +1,5 @@
import ENV from "discourse-common/config/environment";
import { EventTarget } from "rsvp";
import AppEvents from "discourse/services/app-events";
let _skipUpdate;
let _rootElement;
@ -19,6 +19,15 @@ configureEyeline();
// Track visible elements on the screen.
const Eyeline = function Eyeline(selector) {
this.selector = selector;
this.appEvents = AppEvents.create();
};
Eyeline.prototype.on = function(name, cb) {
this.appEvents.on(name, cb);
};
Eyeline.prototype.off = function(name, cb) {
this.appEvents.off(name, cb);
};
Eyeline.prototype.update = function() {
@ -44,6 +53,7 @@ Eyeline.prototype.update = function() {
bottomOffset.top <= docViewBottom && bottomOffset.top >= docViewTop;
}
let { appEvents } = this;
return $elements.each((i, elem) => {
const $elem = $(elem),
elemTop = _rootElement ? $elem.position().top : $elem.offset().top,
@ -68,17 +78,17 @@ Eyeline.prototype.update = function() {
// If you hit the bottom we mark all the elements as seen. Otherwise, just the first one
if (!atBottom) {
this.trigger("saw", { detail: $elem });
appEvents.trigger("saw", { detail: $elem });
if (i === 0) {
this.trigger("sawTop", { detail: $elem });
appEvents.trigger("sawTop", { detail: $elem });
}
return false;
}
if (i === 0) {
this.trigger("sawTop", { detail: $elem });
appEvents.trigger("sawTop", { detail: $elem });
}
if (i === $elements.length - 1) {
return this.trigger("sawBottom", { detail: $elem });
return appEvents.trigger("sawBottom", { detail: $elem });
}
});
};
@ -89,9 +99,9 @@ Eyeline.prototype.flushRest = function() {
return;
}
$(this.selector).each((i, elem) => this.trigger("saw", { detail: $(elem) }));
$(this.selector).each((i, elem) =>
this.appEvents.trigger("saw", { detail: $(elem) })
);
};
EventTarget.mixin(Eyeline.prototype);
export default Eyeline;

View File

@ -1,4 +1,4 @@
import { next, once } from "@ember/runloop";
import { once } from "@ember/runloop";
import DiscourseRoute from "discourse/routes/discourse";
import { ajax } from "discourse/lib/ajax";
import { setting } from "discourse/lib/computed";
@ -11,7 +11,6 @@ import { findAll } from "discourse/models/login-method";
import { getOwner } from "discourse-common/lib/get-owner";
import { userPath } from "discourse/lib/url";
import Composer from "discourse/models/composer";
import { EventTarget } from "rsvp";
function unlessReadOnly(method, message) {
return function() {
@ -236,14 +235,6 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
}
},
activate() {
this._super(...arguments);
next(function() {
// Support for callbacks once the application has activated
ApplicationRoute.trigger("activate");
});
},
renderTemplate() {
this.render("application");
this.render("user-card", { into: "application", outlet: "user-card" });
@ -298,5 +289,4 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
}
});
EventTarget.mixin(ApplicationRoute);
export default ApplicationRoute;

View File

@ -4,13 +4,13 @@ import { cancel, later, schedule } from "@ember/runloop";
import DiscourseRoute from "discourse/routes/discourse";
import DiscourseURL from "discourse/lib/url";
import { ID_CONSTRAINT } from "discourse/models/topic";
import { EventTarget } from "rsvp";
import Evented from "@ember/object/evented";
const SCROLL_DELAY = 500;
import showModal from "discourse/lib/show-modal";
const TopicRoute = DiscourseRoute.extend({
const TopicRoute = DiscourseRoute.extend(Evented, {
init() {
this._super(...arguments);
@ -332,5 +332,4 @@ const TopicRoute = DiscourseRoute.extend({
}
});
EventTarget.mixin(TopicRoute);
export default TopicRoute;

View File

@ -3,7 +3,10 @@ import Evented from "@ember/object/evented";
import Service from "@ember/service";
export default Service.extend(Evented, {
_events: {},
init() {
this._super(...arguments);
this._events = {};
},
on() {
if (arguments.length === 2) {