ember-changeset
ember-changeset copied to clipboard
ember-inspector silently pollutes `changes`
Changes are silently set to the changeset when ember-inspector is used (?) tracked it down to this line
https://github.com/emberjs/ember-inspector/blob/15f49e5ab04e738ec540550001ad8a1b1537eb70/ember_debug/object-inspector.js#L536
it triggers the proxy set and so changeset.changes
is polluted.
In particular these properties:
_oldWillDestroy
willDestroy
Maybe it would be great to have an inverse of changesetKeys
, a denylist, which the default could be these props
A denyKeys
is a good idea! Perhaps we add that with the default of those two keys. (I've looked at this problem in the past and haven't come up with a reasonable solution)
Great catch @betocantu93
I was going crazy to find the reason. 👍
I got around by using my own default changeset, and extend from it if I need further types
//changesets/default
import { EmberChangeset } from 'ember-changeset';
const DENY_LIST = '_denyListKeys';
const AFTER_CHANGE = 'afterChange';
export class DefaultChangeset extends EmberChangeset {
[DENY_LIST] = ['_oldWillDestroy', 'willDestroy', '_super'];
_setProperty({ key, value, oldValue }) {
if (this[DENY_LIST].includes(key)) return;
super._setProperty({ key, value, oldValue });
//Adds an event for afterChange to hook as observer.
this.trigger(AFTER_CHANGE, key)
}
}
//helpers/changeset
import { helper } from '@ember/component/helper';
import { changeset as wrappedChangesetHelper } from 'ember-changeset/helpers/changeset';
import { DefaultChangeset } from '../changesets/default';
export function changeset(positional, options = {}) {
let opts = {
changeset: DefaultChangeset,
...options,
};
return wrappedChangesetHelper(positional, opts);
}
export default helper(changeset);
Probably worth a PR, because curretnly we only have an allowList through changesetKeys which means you need to pass in all keys to avoid this bug, so I went for the denylist approach. Probably changesetKeys could be also be renamed to allowKeys.
FWIW this is the same issue as https://github.com/poteto/ember-changeset/issues/485
I am having this same issue, grateful if the denylist approach could be considered.
deny list seems like a great idea if someone has the time to contribute!