You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I read through the example below (pulled from https://canjs.com/doc/can-stache.tags.named-partial.html) the first thing that came to mind was this means two different things in the same stache file. It took a moment (more than a glance in this small example) to figure out which one does what.
So I propose a change to extend its semantics. This will make things more explicit and continue to discourage the use of stache constructs that create contexts.
I think this would keep this in {{< addressView}} what you might expect.
==================================
This is an age old problem with stache and other (non-JSX) templates ... what to do with the data argument passed to a renderer/view.
It's odd that data becomes this here:
data = {foo: "bar"};
view = stache("{{this.foo}}");
view(data);
One thing I've thought about is forcing call down folks throat:
data = {foo: "bar"};
view = stache("{{this.foo}}");
view.call(data);
If renderers expected this in stache, everything could make a lot more sense. If you want to call a partial or renderer function in stache and set this then do:
{{ addressView.call(this.address1) }}
If you want to pass an argument, do:
{{ addressView(this.address1) }}
It would be cool if somehow these arguments could be defined in stache:
When I read through the example below (pulled from https://canjs.com/doc/can-stache.tags.named-partial.html) the first thing that came to mind was
this
means two different things in the same stache file. It took a moment (more than a glance in this small example) to figure out which one does what.So I propose a change to extend its semantics. This will make things more explicit and continue to discourage the use of stache constructs that create contexts.
In order to keep this from being a breaking change, the first example would continue to work. And
this
andaddress
would be equal.The text was updated successfully, but these errors were encountered: