mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
afe1407c75
commit
96d026a329
@ -108,7 +108,6 @@ var define, requirejs;
|
|||||||
},
|
},
|
||||||
rsvp: {
|
rsvp: {
|
||||||
default: Ember.RSVP,
|
default: Ember.RSVP,
|
||||||
EventTarget: Ember.RSVP.EventTarget,
|
|
||||||
Promise: Ember.RSVP.Promise,
|
Promise: Ember.RSVP.Promise,
|
||||||
hash: Ember.RSVP.hash,
|
hash: Ember.RSVP.hash,
|
||||||
all: Ember.RSVP.all
|
all: Ember.RSVP.all
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import ENV from "discourse-common/config/environment";
|
import ENV from "discourse-common/config/environment";
|
||||||
import { EventTarget } from "rsvp";
|
import AppEvents from "discourse/services/app-events";
|
||||||
|
|
||||||
let _skipUpdate;
|
let _skipUpdate;
|
||||||
let _rootElement;
|
let _rootElement;
|
||||||
@ -19,6 +19,15 @@ configureEyeline();
|
|||||||
// Track visible elements on the screen.
|
// Track visible elements on the screen.
|
||||||
const Eyeline = function Eyeline(selector) {
|
const Eyeline = function Eyeline(selector) {
|
||||||
this.selector = 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() {
|
Eyeline.prototype.update = function() {
|
||||||
@ -44,6 +53,7 @@ Eyeline.prototype.update = function() {
|
|||||||
bottomOffset.top <= docViewBottom && bottomOffset.top >= docViewTop;
|
bottomOffset.top <= docViewBottom && bottomOffset.top >= docViewTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let { appEvents } = this;
|
||||||
return $elements.each((i, elem) => {
|
return $elements.each((i, elem) => {
|
||||||
const $elem = $(elem),
|
const $elem = $(elem),
|
||||||
elemTop = _rootElement ? $elem.position().top : $elem.offset().top,
|
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 you hit the bottom we mark all the elements as seen. Otherwise, just the first one
|
||||||
if (!atBottom) {
|
if (!atBottom) {
|
||||||
this.trigger("saw", { detail: $elem });
|
appEvents.trigger("saw", { detail: $elem });
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
this.trigger("sawTop", { detail: $elem });
|
appEvents.trigger("sawTop", { detail: $elem });
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
this.trigger("sawTop", { detail: $elem });
|
appEvents.trigger("sawTop", { detail: $elem });
|
||||||
}
|
}
|
||||||
if (i === $elements.length - 1) {
|
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;
|
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;
|
export default Eyeline;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { next, once } from "@ember/runloop";
|
import { once } from "@ember/runloop";
|
||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { setting } from "discourse/lib/computed";
|
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 { getOwner } from "discourse-common/lib/get-owner";
|
||||||
import { userPath } from "discourse/lib/url";
|
import { userPath } from "discourse/lib/url";
|
||||||
import Composer from "discourse/models/composer";
|
import Composer from "discourse/models/composer";
|
||||||
import { EventTarget } from "rsvp";
|
|
||||||
|
|
||||||
function unlessReadOnly(method, message) {
|
function unlessReadOnly(method, message) {
|
||||||
return function() {
|
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() {
|
renderTemplate() {
|
||||||
this.render("application");
|
this.render("application");
|
||||||
this.render("user-card", { into: "application", outlet: "user-card" });
|
this.render("user-card", { into: "application", outlet: "user-card" });
|
||||||
@ -298,5 +289,4 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
EventTarget.mixin(ApplicationRoute);
|
|
||||||
export default ApplicationRoute;
|
export default ApplicationRoute;
|
||||||
|
@ -4,13 +4,13 @@ import { cancel, later, schedule } from "@ember/runloop";
|
|||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import { ID_CONSTRAINT } from "discourse/models/topic";
|
import { ID_CONSTRAINT } from "discourse/models/topic";
|
||||||
import { EventTarget } from "rsvp";
|
import Evented from "@ember/object/evented";
|
||||||
|
|
||||||
const SCROLL_DELAY = 500;
|
const SCROLL_DELAY = 500;
|
||||||
|
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
|
|
||||||
const TopicRoute = DiscourseRoute.extend({
|
const TopicRoute = DiscourseRoute.extend(Evented, {
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
@ -332,5 +332,4 @@ const TopicRoute = DiscourseRoute.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
EventTarget.mixin(TopicRoute);
|
|
||||||
export default TopicRoute;
|
export default TopicRoute;
|
||||||
|
@ -3,7 +3,10 @@ import Evented from "@ember/object/evented";
|
|||||||
import Service from "@ember/service";
|
import Service from "@ember/service";
|
||||||
|
|
||||||
export default Service.extend(Evented, {
|
export default Service.extend(Evented, {
|
||||||
_events: {},
|
init() {
|
||||||
|
this._super(...arguments);
|
||||||
|
this._events = {};
|
||||||
|
},
|
||||||
|
|
||||||
on() {
|
on() {
|
||||||
if (arguments.length === 2) {
|
if (arguments.length === 2) {
|
||||||
|
Loading…
Reference in New Issue
Block a user