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

Replace *variable and %special with scope #304

Closed
2 tasks done
justinbmeyer opened this issue Sep 8, 2017 · 1 comment
Closed
2 tasks done

Replace *variable and %special with scope #304

justinbmeyer opened this issue Sep 8, 2017 · 1 comment
Labels

Comments

@justinbmeyer
Copy link
Contributor

justinbmeyer commented Sep 8, 2017

Note: A discussion of this topic can be found on youtube.

This issue represents a combination of several other issues with the goal of cleaning up some of the uglier, less "handlebars" and "javascript" bits of can-stache.

  • move any non-contextual access or mutations to a reserved scope variable
  • make #with and #each use hash params

Move non-contextual access to a reserved scope variable

*variable => scope.var.variable

Move access to template variables (references scope) to scope.var.. Examples:

<can-import from="date-helpers" value:to="*dateHelpers"/>
{{*dateHelpers.prettyDate( date )}}
=>
<can-import from="date-helpers" value:to="scope.var.dateHelpers"/>
{{scope.var.dateHelpers.prettyDate( date )}}

%special => scope.special

Allow special keys to be looked up directly on scope. Examples:

{{#each items}} {{%index}} {{/each}}
=>
{{#each items}} {{scope.index}} {{/each}}
<div on:click="doSomething( %element, %event, %arguments )"/>
=>
<div on:click="doSomething( scope.element, scope.event, scope.arguments )"/>

Access to other values:

  • Helpers passed to the template scope.helpers.helperName
  • Partials passed to the template scope.partials.partialName
  • Tags passed to the template scope.tags.component-name
  • <can-template name="NAME">s passed to the template scope.templates.NAME
  • Inline partials created in the template scope.partials.partialName
  • The current renderer scope.view

Implementation Details

  1. Each template has a references scope, this should be expanded to be a special object that looks like: {vars: {}, helpers: {}, partials: {}, templates: {}, view: renderer, optionsScope: optionsScope}. This object should be the templateContext.
  • When a partial is looked up on the templateContext, it should look in its partials, and then explore the optionsScope.
  • When a helper is looked up, it should look in its helpers, and then explore the options scope, and then the registered helpers.
  1. scope[can.getKeyValue] needs special rules. It probably should first look up in the references scope, then in the "notContext" contexts, then in the normal contexts.
  2. In 4.0, I would like to change the use of the options arg to renderers template(data, options) to essentially set the templateContext.
  • I'd also like to think about special events being registered. <can-import from="drag-drop" value:merge-to="scope.events"/>

make #with and #each use hash params

imaustink added a commit that referenced this issue Oct 26, 2017
imaustink added a commit to canjs/can-view-scope that referenced this issue Oct 26, 2017
imaustink added a commit that referenced this issue Oct 26, 2017
imaustink added a commit that referenced this issue Oct 26, 2017
imaustink added a commit that referenced this issue Oct 26, 2017
imaustink added a commit that referenced this issue Oct 26, 2017
imaustink added a commit that referenced this issue Oct 26, 2017
imaustink added a commit that referenced this issue Oct 26, 2017
imaustink added a commit that referenced this issue Oct 26, 2017
phillipskevin pushed a commit that referenced this issue Oct 26, 2017
@phillipskevin
Copy link
Contributor

This is done in major.

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

No branches or pull requests

2 participants