-
Notifications
You must be signed in to change notification settings - Fork 50
Home
Paul Doerwald edited this page Jun 15, 2016
·
5 revisions
If the response to your memberAction
returns the updated state of the object you changed, you can update the store with the following. This assumes a component structure and a JSONAPI interface, although assuming you set up your adapters correctly, it should work with any interface.
The model:
// models/article.js
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { memberAction } from 'ember-api-actions';
export default Model.extend({
name: attr('string'),
body: attr('string'),
publish: memberAction({
path: 'publish',
type: 'put'
})
});
and the component:
// components/one-article/component.js
import Ember from 'ember';
export default Ember.Component.extend({
store: Ember.inject.service(),
actions: {
publish() {
this.get('article').publish().then((response) => {
this.get('store').push(this.get('store').normalize('article', response.data));
});
}
}
});