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

root context bleeds into compiled function parameters #269

Closed
rsbondi opened this issue Jan 26, 2017 · 4 comments
Closed

root context bleeds into compiled function parameters #269

rsbondi opened this issue Jan 26, 2017 · 4 comments
Labels
Milestone

Comments

@rsbondi
Copy link

rsbondi commented Jan 26, 2017

REPL

{{#each cats.filter(function(c) { return c.name!='Maru' }) as cat}}

compiles to

root.cats.filter(function(root.c) {return root.c.name!='Maru'}

@dxlbnl
Copy link
Contributor

dxlbnl commented Jan 26, 2017

I'd say it's better to use a computed block for this.

{
  computed: {
    cats_filter: cats => cats.filter(...)
  }
}

@Rich-Harris
Copy link
Member

Ah, yes. Hadn't anticipated function expressions inside tags. It could be made to work — would need to do an initial pass on the code to annotate it with scopes so that we can identify that c is a local variable and leave it alone.

The much simpler alternative would be to disallow [arrow] function expressions in tags. That would have a theoretical performance benefit (the mapping function would only need to be created once), though it does mean you would need to add a computed property as per @neoel's example, or add a helper:

{{#each cats.filter(notMaru) as cat}}
  <!-- ... -->
{{/each}}

<script>
  export default {
    helpers: {
      notMaru: cat => cat.name !== 'Maru'
    }
  };
</script>

Not totally sure which is the best option!

@PaulBGD
Copy link
Member

PaulBGD commented Feb 6, 2017

@Rich-Harris I think it'd be worth to add support for it, but adding it as a helper seems to be the best option for performance + reusability.

@Rich-Harris Rich-Harris added this to the ASAP milestone Mar 1, 2017
Rich-Harris added a commit that referenced this issue Mar 2, 2017
allow [arrow] function expressions inside tags
@Rich-Harris
Copy link
Member

This is fixed in 1.9.1 — thanks

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

4 participants