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

Calling a CanMap constructor creates a binding on __keys #106

Closed
phillipskevin opened this issue Jul 19, 2018 · 0 comments · Fixed by #107
Closed

Calling a CanMap constructor creates a binding on __keys #106

phillipskevin opened this issue Jul 19, 2018 · 0 comments · Fixed by #107

Comments

@phillipskevin
Copy link
Contributor

phillipskevin commented Jul 19, 2018

Calling a CanMap constructor inside of a getter sets up a binding on __keys for the created instance, which means that setting any property on that instance will cause the getter to rerun.

    import { CanMap } from "//unpkg.com/can@5/ecosystem.mjs";

    const OtherMap = CanMap.extend({});

    const MyMap = CanMap.extend({
      define: {
        foo: {
          get() {
            // calling this constructor sets up a binding on __keys
            return new OtherMap();
          }
        }
      }
    });

    var map = new MyMap();
    map.on('foo', () => {});
    map.attr('foo.bar', 'baz'); // triggers a `__keys` event on the `OtherMap`, which causes the `foo` getter to rerun
    console.log( map.attr('foo.bar') ); // -> undefined because `foo` is a new `OtherMap` instance

This happens because the constructor calls canReflect.assignDeep, which ends up calling getOwnEnumerableKeys, which creates this binding:

ObservationRecorder.add(this, '__keys');

I think this is a regression from 2.3, where this did not happen.

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

Successfully merging a pull request may close this issue.

1 participant