Skip to content

Instantly share code, notes, and snippets.

@siwalikm
Last active March 18, 2019 06:23
Show Gist options
  • Save siwalikm/8effd8d687d30fb2b9494863481befef to your computer and use it in GitHub Desktop.
Save siwalikm/8effd8d687d30fb2b9494863481befef to your computer and use it in GitHub Desktop.
Reset dirty attributes in Emberjs
const { get, String, inject: { service } } = Ember;
export default Component.extend({
store: inject.service(),
// Note: As we are using pushPayload to modify data directy in store, rollback won't be possible.
// Use https://github.com/offirgolan/ember-data-copyable to clone your model and restore if needed.
actions: {
// some action which get's triggered on some change which makes our model dirty.
someAction() {
// handle something
this.resetDirtyAttributes();
}
},
resetDirtyAttributes() {
let blog = get(this, 'blog');
let payload = {};
payload[String.pluralize(get(blog, 'constructor.modelName'))] = [
Object.assign({ id: blog.id }, camelcaseToUnderscore(article.toJSON()))
];
get(this, 'store').pushPayload(payload);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment