CPLAT-11374: Add makeMapStateToProps/WithOwnProps and makeMapDispatchToProps/WithOwnProps#618
Conversation
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
| log.onRecord.listen((rec) { | ||
| if (rec.level == Level.WARNING) { | ||
| window.console.warn('${log.name} [${rec.level.name}]: ${rec.message}'); | ||
| callMethod(windowConsole, 'warn', ['${log.name} [${rec.level.name}]: ${rec.message}', if (rec.error != null) rec.error]); |
There was a problem hiding this comment.
changed to this to allow for "grouping" the error with the warning using console.warns varargs
| connectOptions.areMergedPropsEqual = allowInterop(handleAreMergedPropsEqual); | ||
| } | ||
|
|
||
| dynamic interopMapStateToPropsHandler() { |
There was a problem hiding this comment.
typed return as dynamic in case we ever want to allow for the object based syntax
There was a problem hiding this comment.
Can you make this a code comment?
greglittlefield-wf
left a comment
There was a problem hiding this comment.
Looks awesome, just some minor comments!
| unwrapInteropValue(initialJsState), | ||
| jsPropsToTProps(initialJsOwnProps) | ||
| ); | ||
| return allowInteropWithArgCount((jsState) { |
There was a problem hiding this comment.
Can we name this function so that it's easier to tell what this function is in the factory?
| ```dart | ||
| import 'package:over_react/over_react_redux.dart'; | ||
| ``` | ||
| ```dart |
There was a problem hiding this comment.
There's a lot of indentation changes in this file from 4 to 3 in some places and 2 in others.
Was there a reason to move away from 4? Can we at least make it consistent?
| connectOptions.areMergedPropsEqual = allowInterop(handleAreMergedPropsEqual); | ||
| } | ||
|
|
||
| dynamic interopMapStateToPropsHandler() { |
There was a problem hiding this comment.
Can you make this a code comment?
| UiFactory<TProps> Function(UiFactory<TProps>) connect<TReduxState, TProps extends UiProps>({ | ||
| Map Function(TReduxState state) mapStateToProps, | ||
| Map Function(TReduxState state, TProps ownProps) mapStateToPropsWithOwnProps, | ||
| Map Function(TReduxState state) Function(TReduxState initialState, TProps initialOwnProps) makeMapStateToProps, |
There was a problem hiding this comment.
Can we throw ArgumentError when a consumer specifies a "make" version as well as a non-"make" version?
Currently if they did both, one would silently be ignored
| - Does a shallow Map equality check by default. | ||
| - Takes a function with the signature `(next: TProps, prev: TProps) => bool`. | ||
| - Can be passed in for small performance improvements. Two possible cases are to implement `deepEqual` or | ||
| `strictEqual`. > See: <https://react-redux.js.org/api/connect#aremergedpropsequal-next-object-prev-object-boolean> |
There was a problem hiding this comment.
This got messed up after formatting
Co-authored-by: Greg Littlefield <greg.littlefield@workiva.com>
…com/Workiva/over_react into CPLAT-11374-add-makeMapStateToProps
Co-authored-by: Greg Littlefield <greg.littlefield@workiva.com>
|
QA +1 |
|
@Workiva/release-management-p |
Motivation
React Redux allows you to return a function from mapStateToProps, allowing you to create a closure specific to that component instance, allowing you to set up a private copy of a memoized selector so that components don't invalidate each other's cache.
We should support this functionality so that consumers can follow the official React Redux tutorials for preventing unnecessary rerenders
Changes
makeMapStateToProps&makeMapStateToPropsWithOwnPropsmakeMapDispatchToProps&makeMapDispatchToPropsWithOwnPropsmakefactory functionsmakeargumentsmakeargumentsRelease Notes
makeMapStateToProps&makeMapStateToPropsWithOwnPropsmakeMapDispatchToProps&makeMapDispatchToPropsWithOwnPropsReview
See CONTRIBUTING.md for more details on review types (+1 / QA +1 / +10) and code review process.
Please review:
QA Checklist
Merge Checklist
While we perform many automated checks before auto-merging, some manual checks are needed: