Skip to content

Commit 1991848

Browse files
committed
Pass child monitor states
Related to #2
1 parent bcf2dbf commit 1991848

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/FilterMonitor.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { cloneElement, Component, PropTypes } from 'react';
2+
import reducer from './reducers';
23

34
export default class FilterMonitor extends Component {
4-
static update = () => ({});
5+
static update = reducer;
56

67
static propTypes = {
78
children: PropTypes.element,
@@ -10,23 +11,28 @@ export default class FilterMonitor extends Component {
1011
};
1112

1213
render() {
13-
const { whitelist, blacklist, children, ...childProps } = this.props;
14+
const { whitelist, blacklist, monitorState, children, ...rest } = this.props;
1415

1516
if (whitelist || blacklist) {
16-
let { stagedActionIds, actionsById } = childProps;
17+
let { stagedActionIds, actionsById } = rest;
1718
stagedActionIds = stagedActionIds.filter(id => {
1819
const action = actionsById[id].action;
1920
return (
2021
whitelist && whitelist.indexOf(action.type) !== -1 ||
2122
blacklist && blacklist.indexOf(action.type) === -1
2223
);
2324
});
24-
childProps = {
25-
...childProps,
25+
26+
rest = {
27+
...rest,
2628
stagedActionIds: stagedActionIds
2729
};
2830
}
2931

32+
const childProps = {
33+
...rest,
34+
monitorState: monitorState.childMonitorState || {}
35+
};
3036
return cloneElement(children, childProps);
3137
}
3238
}

src/reducers.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function childMonitorState(props, state, action) {
2+
const child = props.children;
3+
return child.type.update(child.props, state, action);
4+
}
5+
6+
export default function reducer(props, state = {}, action) {
7+
return {
8+
childMonitorState: childMonitorState(props, state.childMonitorState, action)
9+
};
10+
}

0 commit comments

Comments
 (0)