Skip to content

Instantly share code, notes, and snippets.

@grapho
Last active May 6, 2016 19:33
Show Gist options
  • Select an option

  • Save grapho/457cb6c0e222240a82511aa6e5295f2f to your computer and use it in GitHub Desktop.

Select an option

Save grapho/457cb6c0e222240a82511aa6e5295f2f to your computer and use it in GitHub Desktop.
save promise alias
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
isSaving: Ember.computed.alias('promise.isPending'),
reason: Ember.computed.alias('promise.reason'),
bork() { alert('thing borked!'); },
actions: {
saveAThing() {
let thing = this.store.createRecord('thing');
let saveThing = thing.save();
thing.on('becameError', () => { this.bork() } );
this.set('promise', saveThing);
}
}
});
import Model from 'ember-data/model';
export default Model.extend({
//becameError() {
// alert('i borked!');
//}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
Thing is saving: {{isSaving}}
<br>
<br>
{{#if reason}}
Thing failed: {{reason}}
{{/if}}
<br>
<br>
<button {{action "saveAThing"}}>Save</button>
{
"version": "0.8.0",
"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.5.1",
"ember-data": "2.5.2",
"ember-template-compiler": "2.5.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment