Created
December 21, 2015 17:39
-
-
Save lcoq/e0292cc34f28a3593daa to your computer and use it in GitHub Desktop.
[email protected] observers are not called when a new post comment is saved
This file contains hidden or 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/1', | |
responseText: { | |
'data': { | |
'id': '1', | |
'type': 'post', | |
'attributes': { | |
'name': "1st post" | |
}, | |
'relationships': { | |
'comments': { | |
'data': [], | |
'links': { | |
'related': "/posts/1/comments", | |
'self': "/posts/1/relationships/comments" | |
} | |
} | |
} | |
} | |
} | |
}); | |
$.mockjax({ | |
url: '/comments', | |
responseText: { | |
'data': { | |
'id': '1', | |
'type': 'comment' | |
}, | |
'relationships': { | |
'post': { | |
'links': { | |
'related': "/comments/1/game", | |
'self': "/comments/1/relationships/game" | |
} | |
} | |
} | |
} | |
}); | |
}, | |
post: Ember.computed(function() { | |
return this.store.findRecord('post', '1'); | |
}), | |
postCommentsIdChanged: Ember.observer('[email protected]', function() { | |
console.log('[email protected] changed'); | |
}), | |
actions: { | |
buildComment() { | |
this.get('post').then((post) => { | |
let comment = this.store.createRecord('comment', { post: post }); | |
this.set('newComment', comment); | |
}); | |
}, | |
saveComment() { | |
let comment = this.get('newComment'); | |
console.log('will save, [email protected] should change soon'); | |
comment.save().then( () => { | |
let post = this.get('post'); | |
console.log('did save, [email protected] observers should be called'); | |
console.log('posts.comments.length: ' + post.get('comments.length')); | |
console.log('posts.comments ids: [' + post.get('comments').mapBy('id') + ']'); | |
}); | |
} | |
} | |
}); |
This file contains hidden or 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({ | |
content: DS.attr(), | |
post: DS.belongsTo('post') | |
}); |
This file contains hidden or 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(), | |
comments: DS.hasMany('comment') | |
}); |
This file contains hidden or 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