-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Path customization #2877
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
Merged
Merged
Path customization #2877
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jashkenas
approved these changes
Sep 21, 2020
Thanks for the quick review and approval, @jashkenas! |
joshuacc
reviewed
Sep 21, 2020
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.
Looks great!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the first follow-up on documentcloud/underscore-contrib#231. The next (and final) follow-up will be a PR to Contrib.
I should emphasize that the behavior of paths in Underscore stays the same. That is, full-blown array paths (
['a', 0, 'b']
) remain supported while shorthand string paths ('a.0.b'
) remain unsupported.The purpose of this PR is to add a customization point,
_.toPath
, which users can override, similar to_.iteratee
. The most obvious application of such an override would be to enable string paths, though in principle, users can do something completely different._.toPath
is used internally throughout Underscore.The follow-up PR to Contrib will add a function to its public interface, which users can optionally use to override
_.toPath
. Using that optional override will cause all functions in Underscore and Contrib to support string paths in a uniform way. As long as users don't do this, all functions in Underscore and Contrib will only support array paths. This will be a slightly breaking change for Contrib, but it will be a major step up in consistency between the libraries as well as within Contrib. The future Fusion library will use this mechanism, too, in order to support legacy code that depends on Lodash. Assuming the PR gets approved, of course.This PR also adds one other function,
_.get
, which could be regarded a dual to_.has
as well as a simpler counterpart to_.result
that doesn't invoke methods. This function makes it easier to inherit Underscore's deep property extraction logic in Contrib and Fusion.Some more functional relations:
@jashkenas Please let me know if anything is unclear.
@joshuacc FYI.