canjs / can-view-import

Import dependencies in CanJS views
https://canjs.com/doc/can-view-import.html
MIT License
3 stars 2 forks source link

importPromise should be added "above" current scope #102

Open phillipskevin opened 6 years ago

phillipskevin commented 6 years ago

can-view-import adds the importPromise at the "end" of the scope chain as a "notContext" scope: https://github.com/canjs/can-view-import/blob/6d43973661130ba16040fe4243896c0606de741b/can-view-import.js#L41.

This means that if you have code like this:

    {{#with(app=this)}}
        <can-import from="~/my-footer/my-footer">
            {{#if(isResolved)}}
                <my-footer app:from="app" />
            {{/if}}
        </can-import>
    {{/with}}

This is how the scope is set up:

image

This means that you can't read app without doing ../app.

If we switched the order of these scopes, you would be able to read app and you would also be able to read from importPromise because can-view-scope will walk up the scope chain if the parent is a notContext scope: https://github.com/canjs/can-view-scope/blob/06b22d097ea0ae4204f8e74947e96ddebaf2f905/can-view-scope.js#L286

phillipskevin commented 6 years ago

If this were added "above" the current scope, it would work similarly to how other notContext scopes are set up: https://github.com/canjs/can-stache/blob/master/helpers/core.js#L92-L95