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

This commit is contained in:
David Taylor 2024-08-28 17:06:34 +01:00 committed by GitHub
parent a0d2cb052e
commit 7210f36801
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 23 deletions

View File

@ -19,7 +19,7 @@ export function configureEyeline(opts) {
configureEyeline(); configureEyeline();
// Track visible elements on the screen. // Track visible elements on the screen.
export default EmberObject.extend(Evented, { export default class Eyeline extends EmberObject.extend(Evented) {
update() { update() {
if (_skipUpdate) { if (_skipUpdate) {
return; return;
@ -81,5 +81,5 @@ export default EmberObject.extend(Evented, {
return this.trigger("sawBottom", { detail: $elem }); return this.trigger("sawBottom", { detail: $elem });
} }
}); });
}, }
}); }

View File

@ -10,52 +10,50 @@ export function Placeholder(viewName) {
this.viewName = viewName; this.viewName = viewName;
} }
export default EmberObject.extend(EmberArray, { export default class PostsWithPlaceholders extends EmberObject.extend(
posts: null, EmberArray
_appendingIds: null, ) {
posts = null;
init() { _appendingIds = {};
this._appendingIds = {};
},
@discourseComputed @discourseComputed
length() { length() {
return ( return (
this.get("posts.length") + Object.keys(this._appendingIds || {}).length this.get("posts.length") + Object.keys(this._appendingIds || {}).length
); );
}, }
nextObject(index) { nextObject(index) {
return this.objectAt(index); return this.objectAt(index);
}, }
_changeArray(cb, offset, removed, inserted) { _changeArray(cb, offset, removed, inserted) {
arrayContentWillChange(this, offset, removed, inserted); arrayContentWillChange(this, offset, removed, inserted);
cb(); cb();
arrayContentDidChange(this, offset, removed, inserted); arrayContentDidChange(this, offset, removed, inserted);
this.notifyPropertyChange("length"); this.notifyPropertyChange("length");
}, }
clear(cb) { clear(cb) {
this._changeArray(cb, 0, this.get("posts.length"), 0); this._changeArray(cb, 0, this.get("posts.length"), 0);
}, }
appendPost(cb) { appendPost(cb) {
this._changeArray(cb, this.get("posts.length"), 0, 1); this._changeArray(cb, this.get("posts.length"), 0, 1);
}, }
removePost(cb) { removePost(cb) {
this._changeArray(cb, this.get("posts.length") - 1, 1, 0); this._changeArray(cb, this.get("posts.length") - 1, 1, 0);
}, }
insertPost(insertAtIndex, cb) { insertPost(insertAtIndex, cb) {
this._changeArray(cb, insertAtIndex, 0, 1); this._changeArray(cb, insertAtIndex, 0, 1);
}, }
refreshAll(cb) { refreshAll(cb) {
const length = this.get("posts.length"); const length = this.get("posts.length");
this._changeArray(cb, 0, length, length); this._changeArray(cb, 0, length, length);
}, }
appending(postIds) { appending(postIds) {
this._changeArray( this._changeArray(
@ -67,7 +65,7 @@ export default EmberObject.extend(EmberArray, {
0, 0,
postIds.length postIds.length
); );
}, }
finishedAppending(postIds) { finishedAppending(postIds) {
this._changeArray( this._changeArray(
@ -79,16 +77,16 @@ export default EmberObject.extend(EmberArray, {
postIds.length, postIds.length,
postIds.length postIds.length
); );
}, }
finishedPrepending(postIds) { finishedPrepending(postIds) {
this._changeArray(function () {}, 0, 0, postIds.length); this._changeArray(function () {}, 0, 0, postIds.length);
}, }
objectAt(index) { objectAt(index) {
const posts = this.posts; const posts = this.posts;
return index < posts.length return index < posts.length
? posts[index] ? posts[index]
: new Placeholder("post-placeholder"); : new Placeholder("post-placeholder");
}, }
}); }