Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Workaround for Ember Data hasDirtyAttributes strict equality
/* This is a silly workaround for this https://github.com/emberjs/data/issues/1540 */
import Ember from 'ember';
import DS from 'ember-data';
import _values from 'lodash/object/values';
const { computed } = Ember;
export function checkIsActuallyDirty(diff) {
const [val1, val2] = diff;
// intentional double equal comparison
if (val1 == val2) { /* jshint ignore:line */
return false;
}
}
export function initialize() {
DS.Model.reopen({
isActuallyDirty: computed('hasDirtyAttributes', function() {
let isActuallyDirty = false;
if (this.get('hasDirtyAttributes')) {
const changedAttrs = _values(this.changedAttributes());
isActuallyDirty = changedAttrs.any(function(diff) {
return checkIsActuallyDirty(diff);
});
}
return isActuallyDirty;
}),
});
}
export default {
name: 'ember-data-is-actually-dirty',
initialize,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.