-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[FEATURE property-brace-expansion-improvement] Potential improvement as per #4605 #4617
[FEATURE property-brace-expansion-improvement] Potential improvement as per #4605 #4617
Conversation
Amazing man! this is exactly what I want, I think that with the new property brace expansion the dependent keys will be more declaratives and less verbose. 👍 for you! |
@hjdivad you did the initial implementation of our current expansion can you +1/-1 ? |
also this should be labeled |
How exactly would I put this behind a feature flag? It improves (replaces) existing stable functionality, so I can't disable it without disabling the old functionality too. Should I include both implementations and have it choose the correct one at runtime? |
if (part.indexOf(',') >= 0) { | ||
properties = duplicateAndReplace(properties, part.split(','), index); | ||
} | ||
}); |
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.
Would it not be simpler to splice
new entries rather than duplicateAndReplace
?
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 did the implementation rather quickly, just to test the waters. I'll go ahead and improve the implementation a bit and put it behind a feature flag.
@gordonkristan yeah exactly; if feature then newImpl else oldImpl. I'm 👍 on the feature. I'm slightly confused about the implementation, but maybe there's some good reason why it can't just use |
I updated the code to put it behind feature flags. However, I'm a little confused on how I could use The
So when I'm iterating the parts, I get to the second element of the array. From that point, I need to duplicate the array because the property can't be properly formed until I expand the last element of the array as well. So I have no choice but to turn the above array into the following, and then continue iterating until I get to the last element which also needs expanding.
I could use So that's my reasoning for using the |
I think this is the intended algorithm, partially thought out, to give you the gist:
And if you used a regexp or two, you could avoid all the splits. |
@JulianLeviston I think that's pretty much what I'm doing, only I'm just replacing the item in the array rather than using splice. I'm looping over |
Apologies! :) It seemed simpler to my brain for some reason hehe... nevermind then... :) |
@gordonkristan ah good point about needing to do duplication either way. You are right, the simplification I was thinking about with |
@gordonkristan - Could you rebase? @hjdivad - Am I understanding your last comment correctly as a +1? |
I rebased, so I think it's ready to merge now. |
deepEqual(expected.sort(), foundProperties.sort()); | ||
}); | ||
|
||
if (!IMPROVEMENT_ENABLED) { |
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 you have to explicitly write if (!Ember.FEATURES.isEnabled('property-brace-expansion-improvement')) {
here, as otherwise this won't work with the defeatureify
tool ...
cc @rjackson
[FEATURE property-brace-expansion-improvement] Potential improvement as per #4605
This was go'ed for 🚀 at the core team meeting. We would like to add some documentation to the guides that warns people about how easy it is to add a combinatorial explosion of dependencies. |
I love the property brace expansion introduced in 1.4, but on several occasions I've entered properties with an incorrect syntax. So when @zzarcon mentioned expanding the functionality, I took a stab at it.
Property brace expansion will now work properly with any number of braces in any location, provided that the braces are surrounded by periods and only contain a comma separated list of valid property names (no whitespace).
You can look at the code for examples, but here's the gist:
As far as the algorithm to do the expansion goes, I'm 100% positive that there's a more efficient way. But this way is fairly short and relatively easy to understand, which I think trumps efficiency in this case. However, I'd be glad to improve the algorithm (or anything else) if requested.