javascript - How to delay computed properties to recomputed themselves in Ember.js? -


This question came from the homepage of Ember.js with component example , here's the code:

  App.GravatarImageComponent = Ember.Component.extend ({Size: 200, email: ', gravatarUrl: function () {var email = this.get (' email '), size = This.get ('size'); return 'http://www.gravatar.com/avatar/' + hex_md5 (email) + '? S =' + size;}. Property ('email', 'size') });  

When I try this example, I saw that every time I input a character, the browser will request an avatar. If there are 30 characters in my email address, 30 requests will be removed until the right one is returned to the server. I think it is very inefficient, is not it?

After digging the guides, I did not know that there is a way to solve this problem, so I was wondering: is it possible to say, like 1000ms, a calculated property for Insert? Or is there a better way to deal with this kind of scenario?

You can redeem it, which gives you a similar sense of typing other than Without reacting to anything:

  App.GravatarImageComponent = Ember.Component.extend ({Size: '200, email:', 'fetchEmail, watchEmail: function () {Em.run. Debounce (this, this.setEmail, 400)} .observes ('e-mail'), setEmail: function () {this.set ('fetchEmail', this.get ('e-mail'));}, GravatarUrl : Function () {var email = this.get ('fetchEmail'), size = this.get ('size'); return 'http://www.gravatar.com/avatar/' + MD5 (email) + '? S =' + size;}. Property ('fetchEmail', 'size')});  

Example:


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -