2 ms·
EmberJS uses strings as property paths. You can use 'foo.bar.firstObject.baz' as a unique key the same as any other function that takes a property paths (like a
by orf 10y ago
EmberJS uses strings as property paths. You can use 'foo.bar.firstObject.baz' as a unique key the same as any other function that takes a property paths (like a computed property). In Ember you write a lot of these so any small overhead like a lambda is a bit of a waste.
Also I don't think ember would work with functions instead of strings, the whole point of the strings is that the unique function is only called when one of the items in the property paths changes, and you can't get that from functions. You can only evaluate them.
- Longwelwind 10y agoThanks, I didn't know that Ember did more than just fetching the value. About time wasted, I feel like in the long run, you gain more time by writing statically analyzable code. If you make a typo in the string, you would have to build/transpile+launch the code in order to see the error. Additionaly, if you ever refactor the name of the property, the linter will directly tell you that "value" in the lambda must be changed.
- orf 10y agoI agree and one of the downsides is exactly this. I've felt this pain before :( But there is no way around it - property keys are strings because they can be many layers deep (`foo.bar.test.abc`), and if any of those are undefined then the result is undefined. Also any of those properties (`foo`, `bar`, `test` or `abc`) could be themselves computed properties that depend on others. You also get features like `@each`, used for arrays like `foo.@each.bar`. Perhaps a good middleground would be to do something like C#'s LINQ stuff, where the lambdas are analysed and the values extracted.