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();
// 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 });
}
});
},
});
}
}

View File

@ -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");
},
});
}
}