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

Dynamically-scoped variable accessors #294

Closed
wants to merge 1 commit into from

Conversation

ef4
Copy link
Contributor

@ef4 ef4 commented Aug 29, 2016

This adds the expressison syntax {{-get-dynamic-var "yourVariableName"}} and the statement syntax {{#-with-dynamic-var "yourVariableName" someValue}}...{{/with-dynamic-var}}.

It's a blocker for a glimmer2-compatible liquid-fire, because we need to read and write the outletState variable.

These are both dash-prefixed to mark them private, but emberjs/rfcs#95 discusses making them public.

This is work-in-progress until @chancancode reviews and we simplify.

@ef4
Copy link
Contributor Author

ef4 commented Aug 29, 2016

Tests broke when I rebased. 640c4e9 is the culprit. Investigating.

@ef4
Copy link
Contributor Author

ef4 commented Aug 29, 2016

Ah, my tests were using with-keywords, which was removed.

with-dynamic-var itself is probably the appropriate replacement.

@rwjblue
Copy link
Member

rwjblue commented Aug 29, 2016

The current build failures look like typescript validation issues. You should be able to replicate with npm run vscode-build.

@ef4
Copy link
Contributor Author

ef4 commented Aug 29, 2016

What is the appropriate type for this to return? ValueReference<any> is no good because UNDEFINED_REFERENCE is not of that type.

  evaluate(vm: VM): ValueReference<any> {
    let scope = vm.dynamicScope();
    if (scope.hasOwnProperty(this.varName)) {
      return scope[this.varName];
    } else {
      return UNDEFINED_REFERENCE;
    }
  }

@ef4
Copy link
Contributor Author

ef4 commented Aug 29, 2016

Looks like maybe PathReference<Opaque> is right, based solely on pattern-matching other places in the codebase.

This adds the expressison syntax `{{-get-dynamic-var "yourVariableName"}}` and the statement syntax `{{#-with-dynamic-var "yourVariableName" someValue}}...{{/with-dynamic-var}}`.

let args: EvaluatedArgs = vm.frame.getArgs();

scope[<any>args.positional.values[0].value()] = args.positional.values[1];
Copy link
Contributor Author

@ef4 ef4 Aug 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this cast to <any> appropriate, or is there a better way to do this?

@chancancode chancancode mentioned this pull request Aug 31, 2016
@chancancode
Copy link
Contributor

Closed in #297

@chancancode chancancode closed this Sep 1, 2016
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

Successfully merging this pull request may close these issues.

3 participants