Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ember-inspector silently pollutes changes #589

Open
betocantu93 opened this issue Apr 17, 2021 · 6 comments
Open

ember-inspector silently pollutes changes #589

betocantu93 opened this issue Apr 17, 2021 · 6 comments

Comments

@betocantu93
Copy link
Contributor

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

@snewcomer
Copy link
Collaborator

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)

@sinankeskin
Copy link

Great catch @betocantu93

I was going crazy to find the reason. 👍

@betocantu93
Copy link
Contributor Author

betocantu93 commented Apr 24, 2021

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.

@patrickberkeley
Copy link

FWIW this is the same issue as #485

@dreamsbond
Copy link

I am having this same issue, grateful if the denylist approach could be considered.

@snewcomer
Copy link
Collaborator

deny list seems like a great idea if someone has the time to contribute!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants