Add parent path to changes map #36
Open
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.
With an arbitrary set of object changes, including keys that contain dots or
slashes, it can be difficult to retrieve, via dot notation, an object whose
property is changing. Consider this set of operations:
The output of the final change is:
Note that it is not exactly trivial to figure out how to update a remote
object based on this information. There is nothing here that would tell you
that of currentPath "a.b.c.e.f", the "a.b" part is a single key.
To help resolve this problem, I have added the parent path to the change
map. With the parent path, an array, it is easy to iterate through the array
beginning at the top-level object, to then add/update/whatever the given
property. With the change, the above test yields, as the final change, the
following, which includes the
parentarray member: