Skip to content

Contextual helpers#208

Closed
cibernox wants to merge 5 commits intoemberjs:masterfrom
cibernox:contextual-helpers
Closed

Contextual helpers#208
cibernox wants to merge 5 commits intoemberjs:masterfrom
cibernox:contextual-helpers

Conversation

@cibernox
Copy link
Contributor

@cibernox cibernox commented Feb 7, 2017

@cibernox cibernox changed the title Allow contextual helpers Contextual helpers Feb 7, 2017
<button title={{helper 'capitalize-str' user.name}}></button> <!-- Invalid invocation -->

{{my-component format-date=(helper "moment-format")}} <!-- Creates closure helper -->
{{my-component format-date=(invoke-helper "moment-format")}} <!-- Invokes helper -->
Copy link

@cursedquail cursedquail Feb 8, 2017

Choose a reason for hiding this comment

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

What happens to the existing syntax for invoking helpers, which for this example would be:

{{my-component format-date=(moment-format)}}

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that would invoke the helper which generates a string that is passed to the component, like today.

- Fixes typos
- Removed references to currently unspecified angle bracket component syntax
@knownasilya
Copy link
Contributor

Yes please, and then deprecate {{my-helper}} so we don't have that ambiguity.. is it a value, component, or helper?

@miguelcobain
Copy link
Contributor

It can be any of those, but there are priorities in its resolution. value, helper and then component, I think.

@knownasilya
Copy link
Contributor

Yes, but from a developer point of view, it's ambiguous. Especially for developers new to Ember.

@miguelcobain
Copy link
Contributor

miguelcobain commented Feb 14, 2017

A bit unrelated to the RFC, I guess, but I'm not sure how to solve that, using handlebars syntax.

@machty
Copy link
Contributor

machty commented Feb 15, 2017

There's an inconsistency in helper lifespans that I've noticed in a few other cases that we might want to consider as part of this RFC: https://ember-twiddle.com/d869daef1f0c2c8e2808a8e60dc06ca3?numColumns=2&openFiles=templates.application.hbs%2Chelpers.count-up.js

@ming-codes
Copy link

An helper is mostly just a function. Can the problem be solved by simply yielding a function (or action)?

{{yield
  (action "capitalize-str")
}}
{{#parent-component as |capitalize-str|}}
  {{child-component helper=capitalize-str}}
{{/parent-component}}

Only down side I see is that you can't create a helper that maintain it's own state.

@cibernox
Copy link
Contributor Author

cibernox commented Mar 6, 2017

@ming-codes I could, and it's what I'm doing for now, but there is no built in way of invoking that helper in the template, so I have to use ember-composable-helper's compute utility.

This proves that it's technically possible, but:

  • Syntax is 👎
  • It doesn't support stateful helpers
  • It doesn't support, like in contextual components, to override passed default values

Hence, I think there is room for a feature here.

@knownasilya
Copy link
Contributor

Does #432 supersede this RFC?

@cibernox
Copy link
Contributor Author

@knownasilya maybe? I haven't seen that until now.

@chancancode
Copy link
Member

As others have pointed out, I think the design and exploration here have been absorbed into #432. Let's move the discussion there. Thanks again @cibernox for pioneering the work in this area!

igorT pushed a commit to igorT/rfcs that referenced this pull request Jun 29, 2019
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.

10 participants