-
Notifications
You must be signed in to change notification settings - Fork 58
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
CPLAT-9720 Connect perf optimizations #462
Merged
Merged
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
782b1f5
Don't call into Dart unnecessarily for equality checks
greglittlefield-wf c0be4ae
Fix JS NPEs when passing null functions into connect options
greglittlefield-wf d47d08e
Add test for memoization of wrapInteropValue and identical states
greglittlefield-wf d0beec3
Fix failing test that expected one extra dispatch for some reason
greglittlefield-wf ca2ad9c
Use `const []` for 0-arg prop children so that JS props.children valu…
greglittlefield-wf e0acaa0
Merge remote-tracking branch 'origin/master' into connect-perf
greglittlefield-wf a0dc668
Optimize/sort imports
greglittlefield-wf d0f5d61
Update doc comments as per CR feedback
greglittlefield-wf 270432f
Only wrap areStatePropsEqual when in dev mode
greglittlefield-wf f750e7f
Add more efficient areMapsShallowIdentical utility, write tests
greglittlefield-wf b84b932
Clarify comment
greglittlefield-wf d9f83b8
Eliminate global/shared test state
greglittlefield-wf 7c3cef1
Fix last remaining global store reference
greglittlefield-wf a1b0216
Run equality_test as part of browser suites, add missing @TestOn()
greglittlefield-wf bdec431
Remove expected duplicate calls
greglittlefield-wf fca7c51
Revert inlining of updateMethodCalls, improve failure message
greglittlefield-wf 70a449e
Remove global redux stores in tests
greglittlefield-wf 737fe22
Clean up flux store to match redux store
greglittlefield-wf 74790ba
Fix expect inside of callback
greglittlefield-wf 9026660
Fix other expects in callbacks
greglittlefield-wf f797f58
Update naming, clean up
greglittlefield-wf 64956b0
Remove unnecessary test
greglittlefield-wf 3f9a9bd
Revert "Remove unnecessary test"
greglittlefield-wf 1adf774
Improve test setup and error messages
greglittlefield-wf c58c3dc
Update test setup to compare rotten apples to rotten apples
greglittlefield-wf 93fb99c
Address CR feedback
greglittlefield-wf 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,10 @@ | |
import 'dart:async'; | ||
import 'dart:html'; | ||
|
||
import 'package:collection/collection.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:over_react/over_react.dart'; | ||
import 'package:over_react/over_react_redux.dart'; | ||
import 'package:over_react/src/util/equality.dart'; | ||
import 'package:redux/redux.dart' as redux; | ||
import 'package:w_flux/w_flux.dart' as flux; | ||
|
||
|
@@ -309,8 +309,6 @@ mixin InfluxStoreMixin<S> on flux.Store { | |
} | ||
} | ||
|
||
bool _shallowMapEquality(Map a, Map b) => const MapEquality().equals(a, b); | ||
|
||
/// A wrapper around the `connect` function that provides a similar API into a Flux store. | ||
/// | ||
/// This is primarily for use while transitioning _to_ `connect` and OverReact Redux. | ||
|
@@ -357,9 +355,9 @@ bool _shallowMapEquality(Map a, Map b) => const MapEquality().equals(a, b); | |
/// If you do not provide [mergeProps], the wrapped component receives {...ownProps, ...stateProps, ...dispatchProps} | ||
/// by default. | ||
/// | ||
/// - [areOwnPropsEqual] does a shallow Map equality check by default. | ||
/// - [areStatePropsEqual] does a shallow Map equality check by default. | ||
/// - [areMergedPropsEqual] does a shallow Map equality check by default. | ||
/// - [areOwnPropsEqual] does an equality check using JS `===` (equivalent to [identical]) by default. | ||
/// - [areStatePropsEqual] does a shallow Map equality check using JS `===` (equivalent to [identical]) by default. | ||
/// - [areMergedPropsEqual] does a shallow Map equality check using JS `===` (equivalent to [identical]) by default. | ||
/// | ||
/// - [context] can be utilized to provide a custom context object created with `createContext`. | ||
/// [context] is how you can utilize multiple stores. While supported, this is not recommended. | ||
|
@@ -569,13 +567,13 @@ UiFactory<TProps> Function(UiFactory<TProps>) | |
} | ||
/*--end usage of cases--*/ | ||
|
||
if (areStatePropsEqual == null) { | ||
const defaultAreStatePropsEqual = _shallowMapEquality; | ||
const propHasher = CollectionLengthHasher(); | ||
bool areStatePropsEqualWrapper(TProps nextProps, TProps prevProps) { | ||
final result = defaultAreStatePropsEqual(nextProps, prevProps); | ||
// In dev mode, if areStatePropsEqual is not specified, pass in a version | ||
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 block of changes are best reviewed with whitespace-agnostic diff |
||
// that warns for common pitfall cases. | ||
assert(() { | ||
if (areStatePropsEqual == null) { | ||
bool areStatePropsEqualWrapper(TProps nextProps, TProps prevProps) { | ||
const propHasher = CollectionLengthHasher(); | ||
|
||
assert(() { | ||
prevProps.forEach((key, value) { | ||
// If the value is the same instance, check if the instance has been mutated, | ||
// causing its hash to be updated | ||
|
@@ -592,14 +590,13 @@ UiFactory<TProps> Function(UiFactory<TProps>) | |
} | ||
}); | ||
|
||
return true; | ||
}()); | ||
|
||
return result; | ||
return areMapsShallowIdentical(nextProps, prevProps); | ||
} | ||
areStatePropsEqual = areStatePropsEqualWrapper; | ||
} | ||
|
||
areStatePropsEqual = areStatePropsEqualWrapper; | ||
} | ||
return true; | ||
}()); | ||
|
||
return connect( | ||
mapStateToProps: mapStateToProps, | ||
|
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// Returns whether maps [a] and [b] have [identical] sets of values for the same keys. | ||
// | ||
// Ported from https://github.com/reduxjs/react-redux/blob/573db0bfc8d1d50fdb6e2a98bd8a7d4675fecf11/src/utils/shallowEqual.js | ||
// | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015-present Dan Abramov | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
bool areMapsShallowIdentical(Map a, Map b) { | ||
greglittlefield-wf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (identical(a, b)) return true; | ||
if (a.length != b.length) return false; | ||
for (final key in a.keys) { | ||
if (!b.containsKey(key)) return false; | ||
if (!identical(b[key], a[key])) return false; | ||
} | ||
return true; | ||
} |
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
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.