Created
December 21, 2015 13:49
-
-
Save lcoq/6ec437cab388294f99ea to your computer and use it in GitHub Desktop.
Ember Data isNew does not change
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({ | |
appName:'Ember Twiddle', | |
init() { | |
this._super(...arguments); | |
$.mockjax({ | |
url: '/posts', | |
responseText: { 'data': { 'id': '1', 'type': 'post' } } | |
}); | |
}, | |
newPost: Ember.computed(function() { | |
return this.store.createRecord('post', { name: 'foo' }); | |
}), | |
newPostIsNewChanged: Ember.observer('newPost.isNew', function() { | |
console.log('newPost.isNew changed'); | |
}), | |
newPostIdChanged: Ember.observer('newPost.id', function() { | |
console.log('newPost.id changed'); | |
}), | |
actions: { | |
saveNewPost() { | |
let post = this.get('newPost'); | |
post.save().then(function() { | |
console.log('newPost saved'); | |
}); | |
} | |
} | |
}); |
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 DS from 'ember-data'; | |
export default DS.Model.extend({ | |
name: DS.attr() | |
}); |
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.4.17", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js", | |
"jquery-mockjax": "https://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment