2017-07-25 109 views
0

我有上面的問題,我試過this,但沒有運氣。商店沒有有效的減速器。反應減少

這裏是我的店:

import { compose, combineReducers, applyMiddleware, createStore } from "redux"; 
import thunkMiddleware from "redux-thunk"; 
import * as activities from "../reducers/activities"; 
import * as location from "../reducers/location"; 

const configureStore = railsProps => { 
    const composedStore = compose(
    applyMiddleware(thunkMiddleware), 
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() 
); 

    const combinedReducers = combineReducers({ 
    location, 
    activities 
    }); 
    return composedStore(createStore)(combinedReducers, railsProps); 
}; 

export default configureStore; 

這裏是我的位置減速機:

import { combineReducers } from "redux"; 
import * as actions from "../constants/constants"; 

const coordinates = (state = {}, action) => { 
    switch (action.type) { 
    case actions.GET_LOCATION_SUCCESS: 
    case actions.GET_LOCATION_REQUEST: 
    case actions.GET_LOCATION_FAILURE: 
    default: 
     return state; 
    } 
}; 

const reducer = coordinates; 

export default reducer; 

這裏是我的活動減速機:

import { combineReducers } from "redux"; 
import * as actions from "../constants/constants"; 

const page = (state = 0, action) => { 
    switch (action.type) { 
    case actions.NEXT_ACTIVITY_PAGE: 
     return action.page < action.totalPages - 1 
     ? action.page + 1 
     : action.page; 
    case actions.PREV_ACTIVITY_PAGE: 
     return action.page > 0 ? action.page - 1 : 0; 
    default: 
     return state; 
    } 
}; 

const activities = (state = {}, action) => { 
    switch (action.type) { 
    case actions.FETCH_ACTIVITIES_SUCCESS: { 
     return state.concat(action.activities); 
    } 
    case actions.FETCH_ACTIVITIES_REQUEST: 

    case actions.FETCH_ACTIVITIES_FAILURE: 

    default: 
     return state; 
    } 
}; 

const reducer = combineReducers({ page, activities }); 

export default reducer; 

我想這事做與combineReducers方法以及我如何導入內容,但我不確定那裏有什麼問題。

感謝

+1

從http://redux.js.org/docs/api/combineReducers.html也許你應該將'import *'替換爲「../ redurs/location」的位置;''用'import location from「../reducers/位置「;'(在'arguments'部分下的鏈接關於該導入語句的頁面中有一個註釋)。 –

回答

1

這是錯誤的:當你減速是默認出口

import * as activities from "../reducers/activities"; 
import * as location from "../reducers/location"; 

以上將出口從文件中的所有命名的出口。

正確:

import activities from "../reducers/activities"; 
import location from "../reducers/location"; 

編輯:

,如果你想從文件導出減速讓他們命名

export const page = (state = 0, action) => { 
    switch (action.type) { 
    ... 
    } 
}; 

export const activities = (state = {}, action) => { 
    switch (action.type) { 
    ... 
    } 
}; 

及更高版本:

import { page, activities } from 'path/to/file.js'; 
+0

在我的活動文件中我有一個'page'和一個'activities' reducer這是否意味着我應該將它們全部放在單獨的文件中? –

+0

如果你覺得在單獨的文件中管理它們會更好,那就去做吧。 – Tomasz

+0

但我該怎麼做,否則,當我只能有一個'導出默認'每個文件,並需要導出'頁面和活動'? –