-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
Add new basic helpers to Ember #388
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes please!
|
||
I propose to move to core at least: | ||
|
||
- `eq` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will that be ==
or ===
semantics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, IMHO, it should be ===
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to maintain backwards compatibility it has to be ===
. And even if compatibility wasn't a concern I'd still prefer triple equal
text/0000-basic-template-helpers.md
Outdated
- `add`, `subtract`, and other arithmetic operators. | ||
- `{{#await promise as |value|}}` to render a block conditionally if a promise resolves or fails. | ||
|
||
If there is interest in them, I advocate creating standalone RFCS for them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this RFC should be scoped to add the mentioned logic helpers, the others would need dedicated discussions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍- lets do it
text/0000-basic-template-helpers.md
Outdated
- RFC PR: (leave this empty) | ||
- Ember Issue: (leave this empty) | ||
|
||
# (RFC title goes here) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the title
|
||
- `array` (there is an RFC for it: https://github.com/emberjs/rfcs/pull/318) | ||
- `add`, `subtract`, and other arithmetic operators. | ||
- `{{#await promise as |value|}}` to render a block conditionally if a promise resolves or fails. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely useful IMHO, but should be a separate RFC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree 😄 👉 👉 👉 http://github.com/tildeio/ember-async-await-helper/
just including the existing open RFC on this topic for cross reference, especially with regards to the “short circuiting”, abd why this needs to be done in core space... 😞 |
@webark I've expanded the information about short circuiting and how it can help making apps do less work. It would be nice if all helpers could short circuit by default, but that's just one of the four reasons to include those helpers into templating engine. I think it's still valuable even disregarding possible optimizations. Allowing all helpers to pull arguments as they use them would be a separate RFC. |
@cibernox thanks. and ya, i don't want to get into a “purity” debate. I (having never used ember truth helpers in many apps) always found that if i wanted to reach for one of these, more often then not it was due to a data structure that needed improvement, or that the chunk of template where i was wanting these warranted a new component itself. I will miss this “convention check”, but i feel the community has clearly spoken in favor of this, and there are clear benefits to including it in core. so i’m 👍 even if it’s with a 😞 |
Why not just make ember-truth-helpers part of the default blueprint? |
@Gaurav0 in the Alternatives section that possibility is discussed and I expose some arguments why I think this should be in the core. |
I also find myself by default installing ember-composable-helpers (https://github.com/DockYard/ember-composable-helpers) whenever starting a new ember applications. If there's an appetite for adding new helpers I'd also advocate for:
|
Totally agree. Have never used them, and found whenever someone on my team tried to add them it was inevitably !DRY and/or like you point out above. If they're going in, I'd much prefer default blueprint over core, so I could remove them. I do agree there are some decent use-cases I've been shown, but in general they require too much discipline to keep things from getting hairy. Or if there was an addition to the ember linter plugin... |
FWIW, we do already have a similar concept in the |
@derekwsgray There is one particular use case that is very annoying to do without some basic logic helpers: {{#each jsonPayload.users as |user|}}
{{#if (eq user.type "admin")}}
Some admin stuff
{{else}}
Non admin stuff.
{{/if}
{{/each}} You want to do some very simple check on every iteration. You can do it creating a component for the loop or wrapping your POJOs (to create a |
@cibernox and this is where this convo in something like discord would probably be better.. or if github did threads, but i think this can easily be an example of the later. You could argue something like But again.. this is something that is very subjective. In regards to the helpers, especially with the “short circuiting” of logic values, and the community desire, needs to be in core. You can still purposely not use them, but that can be a choice for an individual and/or a team. The community has clearly spoken in these RFC’s and the download numbers. |
One of the problems with adding stuff like this to core is what happens when a user defines a helper with the same name? Which one wins? How do we ensure that users update ember-truth-helpers to a version without "core" ones? |
@Gaurav0 From the RFC.
This update can happen in a patch as it's not a breaking change and anyone that has a floating version number will eventually get it. We might want to be smart and detect that if they are only using of the ported helpers (no About what wins, I think we should just do whatever we do today with built-in helpers like |
Doesn't this rely on the user updating to the new patch version of ember-truth-helpers? (Not guaranteed, I feel like I'm the only one at my company who ever tries to yarn upgrade.) |
@Gaurav0 correct, if they don't update and the user-defined helpers clover the default ones (which I don't know if it's the case) they wouldn't get the improvement. @rwjblue any insight on what is the best upgrade path? |
I think that would be a great idea. Of course, it would have to be a deprecation warning in the current 3.x cycle, and an error in 4.x actually. Too late for this situation. Probably needs its own RFC. |
Agree with the first part of @webark - the 'admin' example given is not great. The templates become harder to maintain against code changes as you say. Download numbers don't really sway my opinion (if they did, I'd be using a different framework, har har!). I respect the thought-leaders and proponents of best-practices. If the core ember team thinks this is a good idea, I respect that. |
I don't have any reason to think that the helpers in |
Related discussion here: #479 IMO, we should also add a |
In database systems there is an operation called I could see myself using a {{coalesce @arg1 @arg2 this.value "default value"}} |
I think that a default helper could be nice in cases where false is a valid value. Regardless of that, we must resuscitate the discussion about truthyness. As far as I can remember that was the only controversy /cc @chancancode @wycats |
I think a |
- `gt` and `gte` | ||
- `lt` and `lte` | ||
|
||
Those helpers are very low lever and generally useful in both Ember and Glimmer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those helpers are very low lever and generally useful in both Ember and Glimmer. | |
Those helpers are very low level and generally useful in both Ember and Glimmer. |
Apart from the truthiness discussion, adding more helpers blurs the line between Handlebars and Ember's flavor of Handlebars. I imagine as more added, it will be confusing to user just where to go for documentation on any part of the template they are looking at. An explicitly allowed list of template helpers (or template imports or strict mode #496) would help mitigate this problem, as it would be easier to see where these magic bits come from. Or we could decide this is a moot point, considering that package.json contains "ember-cli-htmlbars" and not "handlebars". |
FWIW, I'd like to see this move forward so that I can support optional dynamic tag name (once implemented) in a template only Glimmer Component from an addon without forcing another dep by using ember-truth-helpers. {{#let (element (or @tagName "div")) as |DynamicElement|}}
<DynamicElement />
{{/let}} I realize I could just make that into an {{#if @tagName}}
{{#let (element @tagName) as |DynamicElement|}}
<DynamicElement ...attributes class="foobar"></DynamicElement>
{{!-- everything here... ---}}
{{/let}}
{{else}}
<div ...attributes class="foobar"></div>
{{!-- would also need to be here --}}
{{/if}} |
@Panman8201 I believe you could just use an inline {{#let (element (if @tagName @tagName "div")) as |DynamicElement|}}
<DynamicElement />
{{/let}} (I'd also like this to move forward, just noting it's not blocking!) |
Glimmer VM and passed to the helpers. This might include computationally expensive computed properties, | ||
or hitting code paths that trigger network requests. | ||
|
||
Implementing helpers like `and` or `or` at a lower lever would allow those helpers to be evaluated in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing helpers like `and` or `or` at a lower lever would allow those helpers to be evaluated in | |
Implementing helpers like `and` or `or` at a lower level would allow those helpers to be evaluated in |
Is something blocking this? It's unclear to me what the status is. |
I raised this in a few recent FW core meetings and it fell to @rwjblue and I to leave some of the feedback here. I'll work to get that done today or Friday. Edit: I swear I'm working on it! Got side tracked by publishing core notes and stuff but I am drafting. Edit: 2 mo. later it is obvious I dropped the ball. Talking with @pzuraq about getting it moving again. |
I'm a new Ember dev and we use @rwjblue's |
Framework core discussed this at the September F2F: https://github.com/emberjs/core-notes/blob/master/ember.js/2019-09/F2F_Ember_Core_Team_20190915.md#basic-helpers-rfc I'll try to summarize: @chancancode left a string of comments above, and he raised a few different points which we think remain unaddressed. That said, I think comments were a bit ad-hoc in their presentation and the F2F conversation may help clarify the over-arching concerns. My goal in raising the discussion at F2F was to try and find a path forward, and I think everyone is aligned on that goal. We all want to see some more convenience helpers added to the core framework. HBS v. JS truthiness,
|
Great to see that this can finally move. My only concern with those helpers obeying handlebars' trutiness semantics is that it is different from what We'd have to plan to allow people to migrate without too much pain. I'm particularly worried about addons that use ember-truth-helpers, not so much about application code. I agree that splitting this RFC into three RFCs makes things easier. The one for the equality operators a the one for numerical comparisons are less controversial as they would be identical to those in Ember-truth-helpers and can be implemented quickly. I'll try to write all/some of those RFCs this week, but by any means if anyone wants to help, by all means, just call dibs on one of them in this thread. |
@mixonic I've open three separate RFCs as suggested, feel free to close this one now. |
Thanks @cibernox! We discussed this in todays core team meeting and are moving this RFC into "FCP to Close" (in favor of the broken out / smaller RFCs). |
Any thoughts on where a |
@Panman82 I would submitted it on its own, as I think it would benefit from focused discussion! |
Rendered