diff --git a/js/forum/src/components/DiscussionList.js b/js/forum/src/components/DiscussionList.js index 18b0e0987..bbb52e0e0 100644 --- a/js/forum/src/components/DiscussionList.js +++ b/js/forum/src/components/DiscussionList.js @@ -179,12 +179,7 @@ export default class DiscussionList extends Component { this.loading = false; this.moreResults = !!results.payload.links.next; - // Since this may be called during the component's constructor, i.e. in the - // 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(); + m.lazyRedraw(); return results; } diff --git a/js/forum/src/components/DiscussionPage.js b/js/forum/src/components/DiscussionPage.js index e66fbe2be..e55fc9424 100644 --- a/js/forum/src/components/DiscussionPage.js +++ b/js/forum/src/components/DiscussionPage.js @@ -149,12 +149,7 @@ export default class DiscussionPage extends mixin(Component, evented) { .then(this.init.bind(this)); } - // Since this may be called during the component's constructor, i.e. in the - // 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(); + m.lazyRedraw(); } /** diff --git a/js/forum/src/components/PostsUserPage.js b/js/forum/src/components/PostsUserPage.js index efe4e36a6..ede930842 100644 --- a/js/forum/src/components/PostsUserPage.js +++ b/js/forum/src/components/PostsUserPage.js @@ -95,9 +95,7 @@ export default class PostsUserPage extends UserPage { this.loading = true; this.posts = []; - // Redraw, but only if we're not in the middle of a route change. - m.startComputation(); - m.endComputation(); + m.lazyRedraw(); this.loadResults().then(this.parseResults.bind(this)); } diff --git a/js/lib/components/ModalManager.js b/js/lib/components/ModalManager.js index e3fd72c7d..a29f4c501 100644 --- a/js/lib/components/ModalManager.js +++ b/js/lib/components/ModalManager.js @@ -81,7 +81,7 @@ export default class ModalManager extends Component { clear() { this.component = null; - m.redraw(); + m.lazyRedraw(); } /** diff --git a/js/lib/utils/patchMithril.js b/js/lib/utils/patchMithril.js index a92f7467d..a86480699 100644 --- a/js/lib/utils/patchMithril.js +++ b/js/lib/utils/patchMithril.js @@ -13,5 +13,15 @@ export default function patchMithril(global) { 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; }