Last active
March 18, 2019 06:23
-
-
Save siwalikm/8effd8d687d30fb2b9494863481befef to your computer and use it in GitHub Desktop.
Reset dirty attributes in Emberjs
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
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