Created
May 6, 2016 16:41
-
-
Save blimmer/cb7425d7bef06b5acb858e5f5f6a9e7a to your computer and use it in GitHub Desktop.
Workaround for Ember Data hasDirtyAttributes strict equality
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
/* 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