mirror of
https://github.com/discourse/discourse.git
synced 2025-02-22 23:11:53 +08:00
REFACTOR: user-posts-stream model (#7657)
This commit is contained in:
parent
388433ec06
commit
63264158cf
@ -1,3 +1,4 @@
|
|||||||
|
import { on } from "ember-addons/ember-computed-decorators";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { url } from "discourse/lib/computed";
|
import { url } from "discourse/lib/computed";
|
||||||
import UserAction from "discourse/models/user-action";
|
import UserAction from "discourse/models/user-action";
|
||||||
@ -5,13 +6,14 @@ import UserAction from "discourse/models/user-action";
|
|||||||
export default Discourse.Model.extend({
|
export default Discourse.Model.extend({
|
||||||
loaded: false,
|
loaded: false,
|
||||||
|
|
||||||
_initialize: function() {
|
@on("init")
|
||||||
|
_initialize() {
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
itemsLoaded: 0,
|
itemsLoaded: 0,
|
||||||
canLoadMore: true,
|
canLoadMore: true,
|
||||||
content: []
|
content: []
|
||||||
});
|
});
|
||||||
}.on("init"),
|
},
|
||||||
|
|
||||||
url: url(
|
url: url(
|
||||||
"user.username_lower",
|
"user.username_lower",
|
||||||
@ -40,7 +42,6 @@ export default Discourse.Model.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
findItems() {
|
findItems() {
|
||||||
const self = this;
|
|
||||||
if (this.loading || !this.canLoadMore) {
|
if (this.loading || !this.canLoadMore) {
|
||||||
return Ember.RSVP.reject();
|
return Ember.RSVP.reject();
|
||||||
}
|
}
|
||||||
@ -48,21 +49,17 @@ export default Discourse.Model.extend({
|
|||||||
this.set("loading", true);
|
this.set("loading", true);
|
||||||
|
|
||||||
return ajax(this.url, { cache: false })
|
return ajax(this.url, { cache: false })
|
||||||
.then(function(result) {
|
.then(result => {
|
||||||
if (result) {
|
if (result) {
|
||||||
const posts = result.map(function(post) {
|
const posts = result.map(post => UserAction.create(post));
|
||||||
return UserAction.create(post);
|
this.content.pushObjects(posts);
|
||||||
});
|
this.setProperties({
|
||||||
self.get("content").pushObjects(posts);
|
|
||||||
self.setProperties({
|
|
||||||
loaded: true,
|
loaded: true,
|
||||||
itemsLoaded: self.get("itemsLoaded") + posts.length,
|
itemsLoaded: this.itemsLoaded + posts.length,
|
||||||
canLoadMore: posts.length > 0
|
canLoadMore: posts.length > 0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(function() {
|
.finally(() => this.set("loading", false));
|
||||||
self.set("loading", false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user