Skip to content

Instantly share code, notes, and snippets.

@chrism
Last active August 11, 2016 10:19
Show Gist options
  • Save chrism/2c54406c37dd890dc119a1c9cae9f315 to your computer and use it in GitHub Desktop.
Save chrism/2c54406c37dd890dc119a1c9cae9f315 to your computer and use it in GitHub Desktop.
Testing async behaviour - 1
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'img',
attributeBindings: ['src'],
simpleLoadImage() {
let img = new Image();
img.src = this.get('src');
img.onload = () => {
this.get('onImageLoad')();
};
},
returnSwatchesOnInsert: Ember.on('didInsertElement', function() {
Ember.run.scheduleOnce('afterRender', this, this.simpleLoadImage);
})
});
import Ember from 'ember';
export default Ember.Controller.extend({
imageLoaded: false,
actions: {
imageLoaded() {
this.set('imageLoaded', true);
}
}
});
<h1>Testing async behaviour</h1>
<h2>1 - Simple async example showing an example use case of image loading</h2>
<p>In this simple example use case we have a component which triggers an action when the image has finished loading</p>
<p>is image loaded: <strong>{{imageLoaded}}</strong></p>
{{async-image src='http://emberjs.com/images/tomsters/sandiego-zoey.png' onImageLoad=(action 'imageLoaded')}}
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment