mirror of
https://github.com/flarum/framework.git
synced 2025-04-25 06:04:04 +08:00
Clean up discussion list retaining mechanism
This commit is contained in:
parent
6b8dfdfb1c
commit
16c6bd4f23
@ -17,24 +17,15 @@ export default class DiscussionList extends Component {
|
||||
this.loading = m.prop(true);
|
||||
this.moreResults = m.prop(false);
|
||||
this.discussions = m.prop([]);
|
||||
this.subtrees = [];
|
||||
|
||||
this.willRedraw();
|
||||
this.refresh();
|
||||
|
||||
app.session.on('loggedIn', this.loggedInHandler = this.refresh.bind(this))
|
||||
}
|
||||
|
||||
willRedraw() {
|
||||
this.subtrees = [];
|
||||
this.addSubtrees(this.discussions());
|
||||
}
|
||||
|
||||
addSubtrees(discussions) {
|
||||
discussions.forEach(discussion => {
|
||||
this.subtrees[discussion.id()] = new SubtreeRetainer(
|
||||
() => discussion.freshness
|
||||
)
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
params() {
|
||||
@ -90,7 +81,9 @@ export default class DiscussionList extends Component {
|
||||
parseResults(results) {
|
||||
m.startComputation();
|
||||
this.loading(false);
|
||||
this.addSubtrees(results);
|
||||
|
||||
results.forEach(discussion => this.subtrees[discussion.id()] = new SubtreeRetainer(() => discussion.freshness));
|
||||
|
||||
[].push.apply(this.discussions(), results);
|
||||
this.moreResults(!!results.payload.links.next);
|
||||
m.endComputation();
|
||||
|
@ -36,6 +36,9 @@ export default class DiscussionPage extends Component {
|
||||
app.store.find('discussions', m.route.param('id'), this.params()).then(this.setupDiscussion.bind(this));
|
||||
|
||||
if (app.cache.discussionList) {
|
||||
if (!(app.current instanceof DiscussionPage)) {
|
||||
app.cache.discussionList.subtrees.map(subtree => subtree.invalidate());
|
||||
}
|
||||
app.pane.enable();
|
||||
app.pane.hide();
|
||||
m.redraw.strategy('diff'); // otherwise pane redraws and mouseenter even is triggered so it doesn't hide
|
||||
|
@ -22,7 +22,7 @@ export default class IndexPage extends Component {
|
||||
|
||||
var params = this.params();
|
||||
if (app.cache.discussionList) {
|
||||
app.cache.discussionList.willRedraw();
|
||||
app.cache.discussionList.subtrees.map(subtree => subtree.invalidate());
|
||||
Object.keys(params).some(key => {
|
||||
if (app.cache.discussionList.props.params[key] !== params[key]) {
|
||||
app.cache.discussionList = null;
|
||||
|
@ -17,7 +17,7 @@ export default class PostComment extends Post {
|
||||
super(props);
|
||||
|
||||
this.postHeaderUser = new PostHeaderUser({post: this.props.post});
|
||||
this.subtree.add(this.postHeaderUser.showCard);
|
||||
this.subtree.check(this.postHeaderUser.showCard);
|
||||
}
|
||||
|
||||
view() {
|
||||
|
@ -4,14 +4,14 @@
|
||||
() => this.props.post.freshness,
|
||||
() => this.showing
|
||||
);
|
||||
this.subtree.add(() => this.props.user.freshness);
|
||||
this.subtree.check(() => this.props.user.freshness);
|
||||
|
||||
// view
|
||||
this.subtree.retain() || 'expensive expression'
|
||||
*/
|
||||
export default class SubtreeRetainer {
|
||||
constructor() {
|
||||
this.clear();
|
||||
this.invalidate();
|
||||
this.callbacks = [].slice.call(arguments);
|
||||
}
|
||||
|
||||
@ -27,11 +27,11 @@ export default class SubtreeRetainer {
|
||||
return needsRebuild ? false : {subtree: 'retain'};
|
||||
}
|
||||
|
||||
add() {
|
||||
check() {
|
||||
this.callbacks = this.callbacks.concat([].slice.call(arguments));
|
||||
}
|
||||
|
||||
clear() {
|
||||
invalidate() {
|
||||
this.old = [];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user