Reputation: 16748
I'm writing an editor for the blog-posts on my homepage.
I'm using Ember's textarea-helper to bind an attribute of my model to the editor. In this textarea I type a post in markdown. Below will the output be automatically rendered (like the Stackoverflow-editor does).
My markdown also contains media-embeds from pages like YouTube or Soundcloud which makes the re-rendering very slow.
How can I limit the re-rendering of the page to like only once every five seconds?
Upvotes: 1
Views: 60
Reputation: 1293
You can use Ember.run.throttle
to avoid updating render markup too often.
Example (see also JsBin):
App.IndexController = Ember.Controller.extend({
markdown: 'this is markdown',
rendered: '',
markdownChanged: function() {
Ember.run.throttle(this, this.renderOutput, 5000);
}.observes('markdown').on('init'),
renderOutput: function(){
this.set('rendered', 'I RENDERED THIS: ' + this.get('markdown'));
}
});
Upvotes: 2