,
}
export const RenderRouteResult: (
@@ -54,6 +54,7 @@ export type RouteProps = {
}
type RenderRouteNodeProps = {
+ isActive: boolean,
isContainer: boolean,
routeDef: RouteDefNode,
routeState: RouteStateNode,
@@ -68,10 +69,21 @@ type RenderRouteNodeProps = {
// shouldComponentUpdate (via PureComponent).
class RenderRouteNode extends PureComponent<*, RenderRouteNodeProps<*>, *> {
render() {
- const {isContainer, routeDef, routeState, setRouteState, path, leafTags, stack, children} = this.props
+ const {
+ isActive,
+ isContainer,
+ routeDef,
+ routeState,
+ setRouteState,
+ path,
+ leafTags,
+ stack,
+ children,
+ } = this.props
const RouteComponent = isContainer ? routeDef.containerComponent : routeDef.component
return (
- r.update('component', child => (
+ r.update('component', child => ({isActive}) => (
- {child}
+ {child({isActive})}
))
)
@@ -154,8 +167,9 @@ function renderRouteStack({
if (routeDef.component) {
// If this path has a leaf component to render, add it to the stack.
- const routeComponent = (
+ const routeComponent = ({isActive}) => (
, *
// renderRouteStack gives us a stack of all views down the current route path.
// This component renders the bottom (currently visible) one.
var viewStack = renderRouteStack({...this.props, path: I.List()})
- return viewStack.last().component
+ return viewStack.last().component({isActive: true})
}
}
diff --git a/shared/settings/index.js b/shared/settings/index.js
index b9c1f0a157ba..b014d44507af 100644
--- a/shared/settings/index.js
+++ b/shared/settings/index.js
@@ -1,13 +1,13 @@
// @flow
import SettingsContainer from './render'
-import {connect} from 'react-redux'
+import pausableConnect from '../util/pausable-connect'
import {switchTo} from '../actions/route-tree'
import {logout} from '../actions/login/creators'
import type {RouteProps} from '../route-tree/render-route'
// $FlowIssue type this connector
-export default connect(
+export default pausableConnect(
(state, {routeSelected, routeLeafTags}: RouteProps<{}, {}>) => ({
badgeNumbers: {}, // TODO add badging logic
selectedTab: routeSelected,
diff --git a/shared/util/pausable-connect.js b/shared/util/pausable-connect.js
new file mode 100644
index 000000000000..0c9b9fc38fef
--- /dev/null
+++ b/shared/util/pausable-connect.js
@@ -0,0 +1,21 @@
+// @flow
+import {createConnect} from 'react-redux/src/connect/connect'
+import defaultSelectorFactory from 'react-redux/src/connect/selectorFactory'
+
+import typeof {connect} from 'react-redux'
+
+function selectorFactory(dispatch, factoryOptions) {
+ const selector = defaultSelectorFactory(dispatch, factoryOptions)
+ let cachedResult
+ const pausableSelector = function(state, ownProps) {
+ if (ownProps.isActive || cachedResult === undefined) {
+ cachedResult = selector(state, ownProps)
+ }
+ return cachedResult
+ }
+ return pausableSelector
+}
+
+const pausableConnect: connect = createConnect({selectorFactory})
+
+export default pausableConnect