You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.
I had an idea for how this might be doable without having to resort to a Babel transform (which I had a few concerns about) while still maintaining the same interface. I gave it a shot and was able to get this to work using a computed property macro and a RegExp.
The idea behind my approach relies on three observations:
The String.prototype.replace function supports having a function passed as a second parameter which lets you dynamically replace a match based on the contents of the match
Computed property macros can be generated with dynamic keys based on the passed value
The approach is then to create a computed property macro which:
Constructs and uses a regular expression to get all properties/paths in the passed template string, then
Uses those properties (after a uniq to avoid duplication) as the dependent keys of the generated computed property, and finally
Uses String.prototype.replace to replace instances of ${property} with the get() lookup of those properties.
I recently watched (and enjoyed!) @serenaf's talk about this addon at EmberCamp London 2016.
I had an idea for how this might be doable without having to resort to a Babel transform (which I had a few concerns about) while still maintaining the same interface. I gave it a shot and was able to get this to work using a computed property macro and a RegExp.
The idea behind my approach relies on three observations:
String.prototype.replace
function supports having a function passed as a second parameter which lets you dynamically replace a match based on the contents of the matchThe approach is then to create a computed property macro which:
uniq
to avoid duplication) as the dependent keys of the generated computed property, and finallyString.prototype.replace
to replace instances of${property}
with theget()
lookup of those properties.You can see my solution in a twiddle (source). For the tests I copied the tests in this project's tests/unit/custom-replace-call-paths-test.js, and they seem to all pass.
The text was updated successfully, but these errors were encountered: