This repository has been archived by the owner on Feb 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Immutable support #323
Merged
Merged
Immutable support #323
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cf6dfde
Add immutable helper to determine if type is immutable
stefvhuynh ffe6ec7
Modify formatData and createAccessor to accomodate immutable data
stefvhuynh cb5ad90
Use same array in reduce instead of generating new array every iteration
stefvhuynh 62a801c
Account for array data inputs
stefvhuynh 2556704
Check for iterable when making string map
stefvhuynh b9e2f03
Whitelist sortKey, eventKey and user-defined sortKey, eventKey and add
stefvhuynh f3bd9ff
Add tests for immutable inputs in data helper
stefvhuynh 8736d5d
Fix lint errors
stefvhuynh c4c63d6
Merge branch 'master' into immutable-support
stefvhuynh 006c6ca
Add immutable test for sort order
stefvhuynh 975b412
Shallowly convert immutable objects to js instead of trimming datum
stefvhuynh bb10881
Add test for immutable createAccessor
stefvhuynh 7d5b59a
Only run tests that could take immutable input twice
stefvhuynh e170cde
Add utility to get length of data and allow shallowToJS to convert
stefvhuynh 13bfa35
Add helper method for parsing datum
stefvhuynh 263bc41
Extend proptype for data to account for immutable
stefvhuynh 2195154
Remove immutable from createAccessor; assume plain js object
stefvhuynh acc132f
Use reduce on props.data when getting string map from data
stefvhuynh c01a246
Clean up data spec
stefvhuynh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import React from "react"; | ||
import { defaults, isFunction, property, omit, reduce } from "lodash"; | ||
import Collection from "./collection"; | ||
import React from "react"; | ||
import Immutable from "./immutable"; | ||
|
||
export default { | ||
getPoint(datum) { | ||
|
@@ -144,7 +145,18 @@ export default { | |
return (x) => x; | ||
} | ||
// otherwise, assume it is an array index, property key or path (_.property handles all three) | ||
return property(key); | ||
return (x) => { | ||
if (Immutable.isImmutable(x)) { | ||
if (Array.isArray(key)) { | ||
return x.getIn(key); | ||
} else if (typeof key === "string") { | ||
return x.getIn(key.split(".")); | ||
} else { | ||
return x.get(key); | ||
} | ||
} | ||
return property(key)(x); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more of a nice-to-have. People could just always specify an accessor function if they are passing in an |
||
}, | ||
|
||
modifyProps(props, fallbackProps, role) { | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export default { | ||
IMMUTABLE_ITERABLE: "@@__IMMUTABLE_ITERABLE__@@", | ||
IMMUTABLE_RECORD: "@@__IMMUTABLE_RECORD__@@", | ||
IMMUTABLE_LIST: "@@__IMMUTABLE_LIST__@@", | ||
IMMUTABLE_MAP: "@@__IMMUTABLE_MAP__@@", | ||
|
||
isImmutable(x) { | ||
return this.isIterable(x) || this.isRecord(x); | ||
}, | ||
|
||
isIterable(x) { | ||
return !!(x && x[this.IMMUTABLE_ITERABLE]); | ||
}, | ||
|
||
isRecord(x) { | ||
return !!(x && x[this.IMMUTABLE_RECORD]); | ||
}, | ||
|
||
isList(x) { | ||
return !!(x && x[this.IMMUTABLE_LIST]); | ||
}, | ||
|
||
isMap(x) { | ||
return !!(x && x[this.IMMUTABLE_MAP]); | ||
}, | ||
|
||
shallowToJS(x) { | ||
return this.isIterable(x) ? x.reduce((prev, curr, key) => { | ||
prev[key] = curr; | ||
return prev; | ||
}, this.isList(x) ? [] : {}) : x; | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these methods should work for |
Oops, something went wrong.
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.
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.
using
reduce
here because js arrays andimmutable
List
s both havereduce
and we can then return a regular array.