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

Fix broken scope walking #183

Closed
BairDev opened this issue Aug 24, 2018 · 5 comments
Closed

Fix broken scope walking #183

BairDev opened this issue Aug 24, 2018 · 5 comments
Assignees

Comments

@BairDev
Copy link

BairDev commented Aug 24, 2018

I think we are stumbling upon a bug in this line.

The code in scope.read goes like

while (parent.isSpecial()) {
    parent = parent._parent;
}

Here parent will be undefined at some point and parent.isSpecial() with

Cannot read property 'isSpecial' of undefined (Chrome)

I'd go with while (parent && parent.isSpecial()) or something similar.

For some context: we are trying to use something like {{#if(myList.length)}} or {{#if(../myList.length)}} in a stache view. The workround is adding a ./ or a this. to the reference like {{#if(./myList.length)}}.

I know that we could and should use {{#each(myList}}...{{else}}...{{/each}}, but sometimes we either don't want to iterate or have a different reason for checking the length of a list before iterating over it, e.g. in a <ul> context.

@justinbmeyer justinbmeyer self-assigned this Aug 24, 2018
@justinbmeyer
Copy link
Contributor

Thanks. On my list for monday.

@justinbmeyer
Copy link
Contributor

Just to make sure I understand, you have something like ../key where there is no parent context?

I'm not sure what we should do here. In some ways an error seems right.

An example might be:

var scope = new Scope({});

scope.read("../key",{ ... })

Should we warn or error?

Thoughts @phillipskevin / @chasenlehara / @matthewp ?

@justinbmeyer
Copy link
Contributor

An error or warning might say:

MyAppView:1: Unable to find key '../key'. There is no context at ... Did you mean ./key?

@matthewp
Copy link
Contributor

With leakScope a template might be used in cases where there is a parent context and in other cases where there is not, so I think a warning.

@justinbmeyer
Copy link
Contributor

Fixed in: https://github.com/canjs/can-view-scope/releases/tag/v4.7.1

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

3 participants