mirror of
https://github.com/flarum/framework.git
synced 2025-05-23 23:29:57 +08:00
Refactor start/endComputation into lazyRedraw method
This commit is contained in:
@ -179,12 +179,7 @@ export default class DiscussionList extends Component {
|
|||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.moreResults = !!results.payload.links.next;
|
this.moreResults = !!results.payload.links.next;
|
||||||
|
|
||||||
// Since this may be called during the component's constructor, i.e. in the
|
m.lazyRedraw();
|
||||||
// middle of a redraw, forcing another redraw would not bode well. Instead
|
|
||||||
// we start/end a computation so Mithril will only redraw if it isn't
|
|
||||||
// already doing so.
|
|
||||||
m.startComputation();
|
|
||||||
m.endComputation();
|
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@ -149,12 +149,7 @@ export default class DiscussionPage extends mixin(Component, evented) {
|
|||||||
.then(this.init.bind(this));
|
.then(this.init.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since this may be called during the component's constructor, i.e. in the
|
m.lazyRedraw();
|
||||||
// middle of a redraw, forcing another redraw would not bode well. Instead
|
|
||||||
// we start/end a computation so Mithril will only redraw if it isn't
|
|
||||||
// already doing so.
|
|
||||||
m.startComputation();
|
|
||||||
m.endComputation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,9 +95,7 @@ export default class PostsUserPage extends UserPage {
|
|||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.posts = [];
|
this.posts = [];
|
||||||
|
|
||||||
// Redraw, but only if we're not in the middle of a route change.
|
m.lazyRedraw();
|
||||||
m.startComputation();
|
|
||||||
m.endComputation();
|
|
||||||
|
|
||||||
this.loadResults().then(this.parseResults.bind(this));
|
this.loadResults().then(this.parseResults.bind(this));
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ export default class ModalManager extends Component {
|
|||||||
clear() {
|
clear() {
|
||||||
this.component = null;
|
this.component = null;
|
||||||
|
|
||||||
m.redraw();
|
m.lazyRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,5 +13,15 @@ export default function patchMithril(global) {
|
|||||||
|
|
||||||
Object.keys(mo).forEach(key => m[key] = mo[key]);
|
Object.keys(mo).forEach(key => m[key] = mo[key]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redraw only if not in the middle of a computation (e.g. a route change).
|
||||||
|
*
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
|
m.lazyRedraw = function() {
|
||||||
|
m.startComputation();
|
||||||
|
m.endComputation();
|
||||||
|
};
|
||||||
|
|
||||||
global.m = m;
|
global.m = m;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user