DEV: Convert eyeline & posts-with-placeholders to native class syntax (#28609)
This commit is contained in:
parent
a0d2cb052e
commit
7210f36801
|
@ -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 });
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue