1
0
mirror of https://github.com/flarum/core.git synced 2025-07-29 12:40:40 +02:00

Refactor composer live previews for better performance

This commit is contained in:
Toby Zerner
2015-07-28 16:06:25 +09:30
parent d445b49d7a
commit 40112ae553
5 changed files with 54 additions and 68 deletions

View File

@@ -42,32 +42,6 @@ export default class ReplyComposer extends ComposerBody {
return items;
}
config(isInitialized, context) {
super.config(isInitialized, context);
if (isInitialized) return;
// Every 50ms, if the content has changed, then update the post's
// editedContent property and redraw. This will cause the preview in the
// post's component to update.
const updateInterval = setInterval(() => {
const discussion = this.props.discussion;
const content = this.content();
if (content === discussion.replyContent) return;
discussion.replyContent = content;
const anchorToBottom = $(window).scrollTop() + $(window).height() >= $(document).height();
m.redraw();
if (anchorToBottom) {
$(window).scrollTop($(document).height());
}
}, 50);
context.onunload = () => clearInterval(updateInterval);
}
/**
* Get the data to submit to the server when the reply is saved.
*