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

Extended DefineList.concat method throws error in a component viewmodel #95

Closed
green3g opened this issue Nov 30, 2016 · 4 comments
Closed
Assignees

Comments

@green3g
Copy link

green3g commented Nov 30, 2016

http://jsbin.com/saqobubevu/edit?html,js,console,output

If I create a new list type that has '#': DefineMapType, and I use that list type in a view model of a component, the error is thrown. It looks like it might be a bug, but I've been wrong before on this, so bear with me :)

Uncaught TypeError: Right-hand side of 'instanceof' is not an object(…)

https://github.com/canjs/can-define/blob/master/list/list.js#L23

Basically, this is what the jsbin looks like:

can.Component.extend({
  viewModel: can.DefineMap.extend({
    items: can.DefineList.extend({
      '#': can.DefineMap.extend({
        text: 'string',
      })
    })
  })
  tag: 'my-tag',
  view: can.stache('{{#each items}}{{text}}{{/each}}')
});
@phillipskevin
Copy link
Contributor

@roemhildtg I think this is a bug and have a PR in to fix it. Until that gets in, you can also make this work by using a static DefineMap property instead of the # prototype property. Basically, change:

let ChildList = can.DefineList.extend('ChildList', {
  '#': Child
});

to

let ChildList = can.DefineList.extend('ChildList', {
  DefineMap: Child
}, {});

I think the way you did it originally is the correct way since it is what is shown in the docs, but just wanted to give you this option in case this is blocking you.

@green3g
Copy link
Author

green3g commented Dec 5, 2016

@phillipskevin sounds good. Thanks for the workaround/fix

@phillipskevin
Copy link
Contributor

@roemhildtg the bug here is that this.constructor.DefineMap was changed to #, so the approach I suggested will not work once this issue is fixed. Sorry for the bad advice. I will have a real fix for you today.

@phillipskevin
Copy link
Contributor

@roemhildtg the fix is released as can-define 1.0.5.

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

2 participants