Skip to content

Instantly share code, notes, and snippets.

@chrism
Created April 13, 2015 14:12
Show Gist options
  • Select an option

  • Save chrism/196d7f587f9f494b6fa2 to your computer and use it in GitHub Desktop.

Select an option

Save chrism/196d7f587f9f494b6fa2 to your computer and use it in GitHub Desktop.
Computed Property
// this works (but doesn't cache the values for image.src, image.width, image.height)
export default Ember.Component.extend({
didInsertElement: function() {
var reader = new FileReader();
reader.onload = () => {
var image = new Image();
image.onload = () => {
this.addImage(image.src, image.width, image.height);
};
image.src = reader.result;
};
reader.readAsDataURL(this.get('file'));
}
});
// this always returned undefined
imageObject: function() {
var file = this.get('file');
if (Ember.isPresent(file)) {
var reader = new FileReader();
reader.onload = () => {
var image = new Image();
image.onload = () => {
var imageObject = {
src: image.src,
width: image.width,
height: image.height
};
return imageObject;
};
image.src = reader.result;
};
reader.readAsDataURL(file);
} else {
return false;
}
}.property('file'),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment