Guarantee isomorphism of flatten and unflatten commands#34
Open
sheerun wants to merge 1 commit intohughsk:masterfrom
Open
Guarantee isomorphism of flatten and unflatten commands#34sheerun wants to merge 1 commit intohughsk:masterfrom
sheerun wants to merge 1 commit intohughsk:masterfrom
Conversation
If no changes are needed when flattening / unflattening,
the same object is returned, saving memory and allowing
for strict equality checks on results of flatten/unflatten.
This commit also adds "shallow" option for unflatten command
that ignores nested "messy" object. It is especially useful
when used with "maxDepth" option of flatten function.
For example, now following is true:
```
var object1 = { "foo": { "bar": { "baz": "buz" } } }
var object2 = flatten(object1, { maxDepth: 2 })
var object3 = unflatten(object2, { shallow: true })
assert(object1.foo.bar === object2['foo.bar'])
assert(object1.foo.bar === object3.foo.bar)
```
Contributor
|
@sheerun For API symmetry, what do you think about i.e. var opts = { maxDepth: 2 }
var object2 = unflatten(flatten(object1, opts), opts)
// or
var opts = { maxDepth: 4 }
var object4 = unflatten(flatten(object3, opts), opts) |
Author
|
The same maxDepth won't work for isomorphic operation. The isomorphic case is: That is for unflatten only |
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
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.
If no changes are needed when flattening / unflattening,
the same object is returned, saving memory and allowing
for strict equality checks on results of flatten/unflatten.
This commit also adds "shallow" option for unflatten command
that ignores nested "messy" object. It is especially useful
when used with "maxDepth" option of flatten function.
For example, now following is true: