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

Don't rely on callerScope to yield #646

Merged
merged 3 commits into from
Sep 12, 2017
Merged

Conversation

mmun
Copy link
Member

@mmun mmun commented Sep 8, 2017

This PR is the first step towards first-class blocks and implementing named blocks RFC. In this PR we make sure that when we push a block onto the evaluation stack we also push the scope that the block is closing over.


A slightly longer explanation...

Prior to this PR, whenever we executed a {{yield}} inside a component, we assumed that the scope that the block closed over was the same scope that invoked the component itself.

In fact at the moment this is always true because there is no way to {{yield}} to a block other than the ones that were syntactically part of the component invocation.

With first-class blocks this changes. First-class blocks means that blocks are values and can be passed around as such. See named blocks RFC for more deatils, but long story short, this means that it is no longer safe to assume that the block's scope is the same as the caller's scope. For example,

{{!-- app.hbs --}}
{{#with "ComponentOne's caller scope" as |message|}}
  <ComponentOne>
    {{message}}
  </ComponentOne>
{{/with}}
{{!-- components/component-one.hbs --}}
{{#with "ComponentTwo's caller scope" as |message|}}
  <ComponentTwo @main=@main />
{{/with}}
{{!-- components/component-two.hbs --}}
{{yield}}

In this setup we'd expect the output to be

<ComponentOne>
  <ComponenTwo>
    ComponentOne's caller scope
  </ComponenTwo>
</ComponentOne>

The concept of caller scope will be removed entirely soon.
@mmun mmun force-pushed the dont-rely-on-callerscope-to-yield branch 2 times, most recently from c18b621 to a63e28d Compare September 12, 2017 00:04
@mmun mmun force-pushed the dont-rely-on-callerscope-to-yield branch from a63e28d to 98fde93 Compare September 12, 2017 00:26
@mmun mmun merged commit 6451acf into master Sep 12, 2017
@mmun mmun deleted the dont-rely-on-callerscope-to-yield branch September 12, 2017 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants