From 7210f36801ff449f462bfe3f2a044ba3422d0ad3 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 28 Aug 2024 17:06:34 +0100 Subject: [PATCH] DEV: Convert eyeline & posts-with-placeholders to native class syntax (#28609) --- .../javascripts/discourse/app/lib/eyeline.js | 6 +-- .../app/lib/posts-with-placeholders.js | 38 +++++++++---------- 2 files changed, 21 insertions(+), 23 deletions(-) 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"); - }, -}); + } +}