-
-
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
Changes from 1 commit
25eb73b
3da4af2
575dfc1
6b7d509
298e77f
c1172ff
eb6810a
ed7368e
b73460a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,86 @@ | ||||||
- Start Date: 2018-10-13 | ||||||
- RFC PR: (leave this empty) | ||||||
- Ember Issue: (leave this empty) | ||||||
|
||||||
# (RFC title goes here) | ||||||
|
||||||
## Summary | ||||||
|
||||||
Add new built-in template helpers to perform basic operations in templates, identical to the | ||||||
helpers in [ember-truth-helpers](https://github.com/jmurphyau/ember-truth-helpers) | ||||||
|
||||||
## Motivation | ||||||
|
||||||
It is a very common necessity to almost every Ember app to perform certain operations like compare | ||||||
by equality, negate a value, or perform boolean operations, and often the most convenient place to | ||||||
do it is in the templates. | ||||||
Because of that, `ember-truth-helpers` is probably the single most installed addon either directly | ||||||
or transitively in the entire ecosystem. | ||||||
|
||||||
The fact that this addon is so popular is very telling and Ember should consider to move into the | ||||||
core of the templating engine at least the most popular helpers. | ||||||
|
||||||
One of the shocking moments developers that are familiar with React, Vue or Angular have when trying Ember | ||||||
is that they cannot, at least out of the box, perform the most basic comparisons and boolean operations | ||||||
they are so used to in JSX or Vue/Angular templates. | ||||||
|
||||||
Furthermore, if the [RFC #367](https://github.com/emberjs/rfcs/pull/367) eventually gets merged, these | ||||||
helpers are the perfect candidates to create adoption friction in the community because of how | ||||||
pervasive its usage it in so many templates. | ||||||
|
||||||
Albeit less important, implementing these helpers in the core _could_ enable clever trickery in the | ||||||
Glimmer VM, like evaluating them at compile time when the arguments are constant. | ||||||
cibernox marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
## Detailed design | ||||||
|
||||||
The process consists on deciding what helpers from `ember-truth-helpers` we consider the most important | ||||||
and move them into Ember.js itself or even the Glimmer VM, in a fully backwards compatible way. | ||||||
|
||||||
I propose to move to core at least: | ||||||
|
||||||
- `eq` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will that be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. If we want to maintain backwards compatibility it has to be |
||||||
- `not` | ||||||
- `and` | ||||||
- `or` | ||||||
- `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 commentThe reason will be displayed to describe this comment to others. Learn more. @cibernox There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
I propose to not move: | ||||||
|
||||||
- `is-array` (uses `Ember.isArray`) | ||||||
- `is-empty` (uses `Ember.isEmpty`) | ||||||
- `is-equal` (uses `Ember.isEqual`) | ||||||
- `xor` (not very common) | ||||||
- `not-eq` (can be expressed as `(not (eq a b)`) | ||||||
|
||||||
When this feature is implemented, we would update `ember-truth-helpers` to not ship the helpers that | ||||||
were moved into the core if the version of Ember is | ||||||
cibernox marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
## How we teach this | ||||||
|
||||||
As any new API, will have to be documented in the guides with examples. | ||||||
|
||||||
## Drawbacks | ||||||
|
||||||
We are increasing the public API of the framework, and every line of code is a liability, although | ||||||
those helpers are extremely straightforward. | ||||||
|
||||||
## Alternatives | ||||||
|
||||||
An alternative path would be to include `ember-truth-helpers` in the default blueprint for apps an | ||||||
addons. | ||||||
|
||||||
## Unresolved questions | ||||||
|
||||||
The main unresolved question is what helpers we deem worthy of being moved into the core, and also | ||||||
if we want any other helpers not mentioned above. | ||||||
|
||||||
Other helpers that come to mind that _could_ also be worth adding: | ||||||
|
||||||
- `array` (there is an RFC for it: https://github.com/emberjs/rfcs/pull/318) | ||||||
cibernox marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- `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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I agree 😄 👉 👉 👉 http://github.com/tildeio/ember-async-await-helper/ |
||||||
|
||||||
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 commentThe 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.
Missing the title