44
55import React , { Component , PropTypes } from 'react' ;
66import Dock from 'react-dock' ;
7- import { connect } from 'react-redux' ;
8- import { combineReducers , bindActionCreators } from 'redux' ;
7+ import { combineReducers } from 'redux' ;
98
109const POSITIONS = [ 'left' , 'top' , 'right' , 'bottom' ] ;
1110
@@ -14,7 +13,7 @@ class DockMonitor extends Component {
1413 monitorState : PropTypes . shape ( {
1514 position : PropTypes . oneOf ( POSITIONS ) . isRequired ,
1615 isVisible : PropTypes . bool . isRequired ,
17- childState : PropTypes . any
16+ child : PropTypes . any
1817 } ) . isRequired ,
1918
2019 monitorActions : PropTypes . shape ( {
@@ -75,7 +74,7 @@ function changePosition() {
7574 return { type : CHANGE_POSITION } ;
7675}
7776
78- export default function create ( ChildMonitor , {
77+ export default function create ( child , {
7978 defaultIsVisible = true ,
8079 defaultPosition = 'right'
8180} = { } ) {
@@ -91,37 +90,27 @@ export default function create(ChildMonitor, {
9190 state ;
9291 }
9392
94- function getChildStore ( store ) {
95- return {
96- ...store ,
97- getState ( ) {
98- const state = store . getState ( ) ;
99- return {
100- ...state ,
101- monitorState : state . monitorState . childState
102- } ;
103- }
104- } ;
105- }
106-
107- const Monitor = connect (
108- state => state ,
109- dispatch => ( {
110- monitorActions : bindActionCreators ( { toggleVisibility, changePosition } , dispatch )
111- } )
112- ) ( DockMonitor ) ;
113-
114- const CompositeMonitor = ( { store } ) => (
115- < Monitor store = { store } >
116- < ChildMonitor store = { getChildStore ( store ) } />
117- </ Monitor >
93+ const ChildMonitor = child . component ;
94+ const CompositeMonitor = ( { monitorState, monitorActions, ...rest } ) => (
95+ < DockMonitor monitorState = { monitorState }
96+ monitorActions = { monitorActions } >
97+ < ChildMonitor { ...rest }
98+ monitorState = { monitorState . child }
99+ monitorActions = { monitorActions . child } />
100+ </ DockMonitor >
118101 ) ;
119102
120- CompositeMonitor . reducer = combineReducers ( {
121- childState : ChildMonitor . reducer ,
122- position,
123- isVisible
124- } ) ;
125-
126- return CompositeMonitor ;
103+ return {
104+ component : CompositeMonitor ,
105+ reducer : combineReducers ( {
106+ position,
107+ isVisible,
108+ child : child . reducer
109+ } ) ,
110+ actionCreators : {
111+ toggleVisibility,
112+ changePosition,
113+ child : child . actionCreators
114+ }
115+ } ;
127116}
0 commit comments