2017-01-16 7 views
0

私はリアクションレミックスのアプリケーションを使っています。レイアウトの中にいくつかの状態とレデューサーを注入する必要があります。私はルートを持っている -自分のレデューサーを使ったリアクション

export const createRoutes = (store) => ({ 
path  : '/', 
component : CoreLayout, 
indexRoute : Index(store), 
childRoutes : [ 
    .... 
] 

と私はエラーを得たので、私は、メソッドのようにそれを使用can`t私のコアレイアウトコンポーネントは、コンポーネントをする必要があります。その無効 -

getComponent (nextState, cb) { 
require.ensure([], (require) => { 
    const Layout= require('./containers/CoreLayoutContainer').default; 
    const reducer= require('../../modules/reducer').default; 

    injectReducer(store, { key: 'layout', reducer}) 

    cb(null, Layout) 
}, 'SongsList') 

そして、私の最大の問題はその私がコンテナ

const mapDispatchToProps = { 
changePlaybackTime: (newTime) => changePlaybackTime(newTime), 
} 

const mapStateToProps = (state) => ({ 
    currentSongId: state.songs.player.currentSongId, 
    isPaused : state.songs.player.isPaused, 
    isPlaying: state.songs.player.isPlaying, 
}) 


export default connect(mapStateToProps, mapDispatchToProps)(CoreLayout) 

と私は現在ルートの中で定義減速の状態を得たmapStateToPropsのすべての時間をレイアウトを作成しようとした場合、そのgetComponent(nextState, cb)メソッド。自分のレデューサーをレイアウトに挿入するにはどうすればいいですか?ありがとう。

UPD:ショーinjectReducer機能:だから

import { combineReducers } from 'redux' 

export const makeRootReducer = (asyncReducers) => { 
    return combineReducers({ 
     //you can add global reducers here and got it everywhere 
     ...asyncReducers 
    }) 
} 

export const injectReducer = (store, { key, reducer }) => { 
    if (Object.hasOwnProperty.call(store.asyncReducers, key)) return 

    store.asyncReducers[key] = reducer 
    store.replaceReducer(makeRootReducer(store.asyncReducers)) 
} 
+0

'injectReducer'定義も表示できますか? reduxコアAPIにそのような機能はありません –

+0

はい、喜んであります。 –

答えて

0

誰もがこの質問を強制するかどうか - そこにレイアウト内dynamyc減速を注入する方法はありませんが、あなたはのライフサイクル全体のための任意の減速を持っている必要がある場合あなたはその減速機をグローバルに注入することができます。

関連する問題