Skip to content

A platform for community discussion. Free, open, simple.

DEV: Convert eyeline & posts-with-placeholders to native class syntax (#28609)

David Taylor7210f36801ff
diff --git a/app/assets/javascripts/discourse/app/lib/eyeline.js b/app/assets/javascripts/discourse/app/lib/eyeline.js
index 2a8113f4c46..ffa55b95e8b 100644
--- a/app/assets/javascripts/discourse/app/lib/eyeline.js
+++ b/app/assets/javascripts/discourse/app/lib/eyeline.js
@@ -19,7 +19,7 @@ export function configureEyeline(opts) {
configureEyeline();
// Track visible elements on the screen.
-export default EmberObject.extend(Evented, {
+export default class Eyeline extends EmberObject.extend(Evented) {
update() {
if (_skipUpdate) {
return;
@@ -81,5 +81,5 @@ export default EmberObject.extend(Evented, {
return this.trigger("sawBottom", { detail: $elem });
}
});
- },
-});
+ }
+}
diff --git a/app/assets/javascripts/discourse/app/lib/posts-with-placeholders.js b/app/assets/javascripts/discourse/app/lib/posts-with-placeholders.js
index d71b301af7e..2748e6aa724 100644
--- a/app/assets/javascripts/discourse/app/lib/posts-with-placeholders.js
+++ b/app/assets/javascripts/discourse/app/lib/posts-with-placeholders.js
@@ -10,52 +10,50 @@ export function Placeholder(viewName) {
this.viewName = viewName;
}
-export default EmberObject.extend(EmberArray, {
- posts: null,
- _appendingIds: null,
-
- init() {
- this._appendingIds = {};
- },
+export default class PostsWithPlaceholders extends EmberObject.extend(
+ EmberArray
+) {
+ posts = null;
+ _appendingIds = {};
@discourseComputed
length() {
return (
this.get("posts.length") + Object.keys(this._appendingIds || {}).length
);
- },
+ }
nextObject(index) {
return this.objectAt(index);
- },
+ }
_changeArray(cb, offset, removed, inserted) {
arrayContentWillChange(this, offset, removed, inserted);
cb();
arrayContentDidChange(this, offset, removed, inserted);
this.notifyPropertyChange("length");
- },
+ }
clear(cb) {
this._changeArray(cb, 0, this.get("posts.length"), 0);
- },
+ }
appendPost(cb) {
this._changeArray(cb, this.get("posts.length"), 0, 1);
- },
+ }
removePost(cb) {
this._changeArray(cb, this.get("posts.length") - 1, 1, 0);
- },
+ }
insertPost(insertAtIndex, cb) {
this._changeArray(cb, insertAtIndex, 0, 1);
- },
+ }
refreshAll(cb) {
const length = this.get("posts.length");
this._changeArray(cb, 0, length, length);
- },
+ }
appending(postIds) {
this._changeArray(
@@ -67,7 +65,7 @@ export default EmberObject.extend(EmberArray, {
0,
postIds.length
);
- },
+ }
finishedAppending(postIds) {
this._changeArray(
@@ -79,16 +77,16 @@ export default EmberObject.extend(EmberArray, {
postIds.length,
postIds.length
);
- },
+ }
finishedPrepending(postIds) {
this._changeArray(function () {}, 0, 0, postIds.length);
- },
+ }
objectAt(index) {
const posts = this.posts;
return index < posts.length
? posts[index]
: new Placeholder("post-placeholder");
- },
-});
+ }
+}