-
-
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
Adding Equality Operators to Templates #560
Changes from 2 commits
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,63 @@ | ||
- Start Date: 2019-12-08 | ||
- Relevant Team(s): (fill this in with the [team(s)](README.md#relevant-teams) to which this RFC applies) | ||
- RFC PR: https://github.com/emberjs/rfcs/pull/560 | ||
- Tracking: (leave this empty) | ||
|
||
# Adding Equality Operators to Templates | ||
|
||
## Summary | ||
|
||
Add new built-in template `{{eq}}` and `{{neq}}` helpers to perform basic equality operations in templates, similar to those included in `ember-truth-helpers`. | ||
|
||
This RFC is a subset of the changes proposed in #388. | ||
|
||
## Motivation | ||
|
||
It is a very common need in any sufficiently complex Ember app to perform some equality operations and often the most convenient place to do it is right in the templates. | ||
Because of that, [ember-truth-helpers](https://github.com/jmurphyau/ember-truth-helpers) is one of the most installed addons out there, either directly by apps or indirectly by | ||
other addons that those apps consume. | ||
|
||
The fact that `ember-truth-helpers` is so popular is a good signal that this it is filling a perceived gap in Ember's functionality. | ||
|
||
A second reason is that it might help make Ember more approachable to newcomers that have some experience in other frameworks. | ||
Most if not all web frameworks have some way of comparing values in the templates and it's surprising that Ember requires an third party package to perform | ||
even the most basic operations. | ||
|
||
|
||
## Detailed design | ||
|
||
Add `{{eq}}` and `{{neq}}` helpers. | ||
|
||
#### `{{eq}}` | ||
Binary operation. Throws an error if not called with exactly two arguments. | ||
Equivalent of <arg1> === <arg2> | ||
This is identical to the `eq` helper in `ember-truth-helpers` | ||
|
||
#### `{{neq}}` | ||
Binary operation. Throws an error if not called with exactly two arguments. | ||
Equivalent of <arg1> !== <arg2> | ||
This is identical to the `not-eq` helper in `ember-truth-helpers`, except for the name. | ||
|
||
This RFC intentionally leaves the implementation details unspecified, those could be implemented in Glimmer VM or | ||
in a higher level in Ember itself. | ||
|
||
## How we teach this | ||
|
||
The introduction of these helpers does not impact the current mental model for Ember applications. | ||
|
||
In addition to API and Guides documentation with illustrative examples of usage of the various helpers. | ||
cibernox marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Drawbacks | ||
|
||
Adding new helpers increases the surface area of the framework and the code the core team commits to support long term. | ||
|
||
## Alternatives | ||
|
||
One alternative path is don't do anything and let users continue to define their own helpers (or install `ember-truth-helpers`). | ||
|
||
## Unresolved questions | ||
|
||
- If an app already use `ember-truth-helpers`, the `{{eq}}` helper will conflict with the one proposed here. How do we | ||
update `ember-truth-helpers` to make sure the helper of the same name doesn't collide with the built-in one? | ||
- The inequality helper proposed in this RFC is `{{neq}}` while the one in ember-truth-helpers is `{{not-eq}}`. It is | ||
worth considering the benefits that keeping the same name might have in helping apps and addon migrate to the built-in helper. | ||
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. this could easily be migrated using a template codemod, so probably not much of an issue in reality :) 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. Sure, but nothing beats not having to change anything 😄 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. @Turbo87 And you have to admit: 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 mean, one could argue that 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. Fair enough, I'm happy with |
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 think we should allow many arguments with
eq
, behaving like: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.
@rwjblue is that consensuated with the core team? I'm fine either way, I just want to be sure before updating it.