Forked from chrism/components.async-image-wrapper.js
Created
August 11, 2016 18:28
-
-
Save dwickern/e767d7889dacc11fa946673c5e573cf7 to your computer and use it in GitHub Desktop.
Non working example using Ember.run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
imageLoaded: 'image not yet loaded', | |
// purely to make sure image loads each time and | |
// is not cached for testing | |
volatileSrc: Ember.computed('src', function(){ | |
return this.get('src') + '?cache=' + new Date().toISOString(); | |
}), | |
actions: { | |
imageLoaded(message) { | |
if (!this.isDestroyed) { | |
this.set('imageLoaded', message); | |
} | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
function loadImagePromise(src) { | |
let img = new Image(); | |
img.src = src; | |
return new Ember.RSVP.Promise(function (resolve, reject) { | |
img.onload = Ember.run(resolve); | |
img.onerror = Ember.run(reject); | |
}); | |
} | |
export default Ember.Component.extend({ | |
tagName: 'img', | |
attributeBindings: ['src'], | |
loadImage() { | |
loadImagePromise(this.get('src')).then(() => { | |
this.get('onImageLoad')("image now loaded"); | |
}); | |
}, | |
didInsertElement() { | |
Ember.run.scheduleOnce('afterRender', this, this.loadImage); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
h1, h2 { | |
//display: none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { moduleForComponent, test } from 'ember-qunit'; | |
import wait from 'ember-test-helpers/wait'; | |
import hbs from 'htmlbars-inline-precompile'; | |
moduleForComponent('async-image-wrapper', 'Demonstrates wait()', { | |
integration: true | |
}); | |
test('Passes if using wait', function(assert) { | |
assert.expect(1); | |
this.render(hbs`{{async-image-wrapper src='http://emberjs.com/images/tomsters/sandiego-zoey.png'}}`); | |
return wait().then( () => { | |
assert.equal(this.$('#image-loaded-text').text(), 'image now loaded'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
setResolver(resolver); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.10.4", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": true | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.6.0", | |
"ember-data": "2.6.0", | |
"ember-template-compiler": "2.6.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment