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

Provide better alternatives to scope.root #159

Closed
phillipskevin opened this issue May 4, 2018 · 3 comments
Closed

Provide better alternatives to scope.root #159

phillipskevin opened this issue May 4, 2018 · 3 comments

Comments

@phillipskevin
Copy link
Contributor

phillipskevin commented May 4, 2018

I have been upgrading a medium sized app from CanJS 2.3 to CanJS 4.0. In the process, I'm removing all of the implicit scope walking. This app had a few properties that were being implicitly read from the application viewModel throughout the application without passing the properties through the component tree. This causes warnings like this one:

"public/app/environment-manager/reports/executive-dashboard/executive-dashboard.stache:44: "propertyName" is not in the current scope, so it is being read from a parent scope.
This will not happen automatically in an upcoming release. See https://canjs.com/doc/can-stache.scopeAndContext.html#PreventingScopeWalking.
Use "../../../../../../../propertyName" or "scope.find('propertyName')" instead.

No one should ever actually use "../../../../../../../propertyName" in a template. There should be a better option.

In this application, propertyName is in the application viewModel. Naively, I thought this is probably scope.root.propertyName, but the scope walking warning would have told me if this were the case.

The problem here is that scope.root is not the "root"... it's not the top-level scope in this application. scope.root actually represents the viewModel of the current component.

Here is what the scopes look like in this app:

image

I propose we:

  • add a scope.viewModel that gives what scope.root gives now
  • add a scope.top that gives the application viewModel (the top-most actual scope)
  • deprecate scope.root
@justinbmeyer
Copy link
Contributor

I'm good with that. Maybe scope.vm? I honestly still would just like viewModel to be a reserved word. It's so insanely common, it's arguably worth it.

@phillipskevin
Copy link
Contributor Author

I'm also thinking maybe scope.app instead of scope.top.

@phillipskevin
Copy link
Contributor Author

Decided scope.app is no good since it will only be that app if leakScope is true all the way down.

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

2 participants