Ember comes with a great deal of tools
to get a job done right out of the box. Most of the time you don’t have to look too far, like the tools on your tool belt, to find the right function or helper that comes as part of the framework. However, like most things in life, these tools need improvements or upgrades to match the ever-changing day-to-day challenges. This week’s RFCs (Request for Comments) aim to add or enhance some of your most used tools.Array functions
: All things Ember.A()
without the Ember.A()
. Ember makes working with arrays
a breeze. mapBy
, the list goes on. These helpful Array methods make for a good developer experience, but they do come at a cost. If Array prototype extensions are disabled (as is the case in FastBoot) it becomes frustrating to defensively wrap every Array in Ember.A()
. Additionally, these methods are wastefully added to the global Array prototype when only a handful of them are ever used. RFC#323
proposes that all Array methods are extracted and exported as similarly named functions
. For example, instead of using Array.mapBy(prop)
, you would use the mirrored function mapBy(array, prop)
On the surface the drawbacks to such an approach would be an increase in Ember’s framework size, but since the conversion is nearly one-to-one, the increase should be negligible.
has finished up the RFC for an array template helper
. This RFC proposes a new template helper for dynamically creating Arrays in templates. The usage is similar to the hash
template helper and helps fill in a hole in the Ember Template API.
An example usage of this helper in a template is: (array 'a' 'b' 'c') which would return the value ['a', 'b', 'c'].
All in all, this is a great addition to the Ember API. While it will add a minuscule size increase to the framework, the hole that it fills makes up for it.Html-Safe-Helper
: Sometimes you need to consume html
to display it in a template. What if that html contained script tags or a malicious iframe? To use this type of content, it’s best to run it through the htmlSafe
function to create a SafeString
. This work is usually done outside of the template, and without a framework provided helper, so you would create a component that is otherwise unnecessary. Moreover, you could install ember-cli-string-helpers
encourages the adoption of a framework provided html-safe helper
. The RFC already has strong support with a majority of the conversation focusing on the naming of the helper and if the triple curlies should be deprecated.Key functions for each / each-in
: The Glimmer VM uses a diffing algorithm to determine when to re-render a loop. The default key strategy used in the algorithm is usually good enough in most cases to detect when a loop has changed. RFC#321
enhances change detection by augmenting the default key strategies with user defined functions. This increased flexibility allows you to assemble composite keys from many different properties of an object or even from properties on objects whose fields are out of your control.
At this point we would like to remind you that the RFC process is a workflow doing just what its name says: asking for comments of the community, also know as you. ❤️Check out any of the RFCs we mentioned above and let your opinion, suggestions and thoughts be heard.