-1
實施意外令牌時減速當我建立使用吞掉我的應用程序,一飲而盡一直給我一個語法錯誤:語法錯誤:在終極版
SyntaxError: /Users/USER/Documents/portfolio_projects/USER_PROJECT/PROJECT/src/main/webapp/src/reducers/AuthorizationReducer.js:
Unexpected token (12:4) while parsing file: /Users/USER/Documents/portfolio_projects/USER_PROJECT/PROJECT/src/main/webapp/src/reducers/AuthorizationReducer.js]
pos: 261,
loc: { line: 12, column: 4 }
AuthorizationReducer.js:
import ActionType from '../actions/ActionType';
const defaultState = {
signedIn: false,
isAuthorizing: false
}
const AuthorizationReducer = (state = defaultState, action) => {
switch(action.type) {
case ActionType.Authorization.REQUEST:
return {
...state,
isAuthorizing: true
};
case ActionType.Authorization.SUCCESS:
return {
...state,
signedIn: true,
isAuthorizing: false
};
case ActionType.Authorization.FAILURE:
return {
...state,
signedIn: false,
isAuthorizing: false
};
}
return state;
}
export default AuthorizationReducer;
ActionType.js
const ActionType = {
Authorization: {
REQUEST: '',
SUCCESS: '',
FAILURE: ''
}
}
const ActionTypeHax: any = ActionType;
Object.keys(ActionTypeHax).forEach(category => {
Object.keys(ActionTypeHax[category]).forEach(actionType => {
ActionTypeHax[category][actionType] = category + '.' + actionType;
});
});
module.export = ActionType;
我只是沒有看到這裏有什麼問題。據我所知,這裏的語法對於實現reducer是正確的。
儘管我沒有配置我的轉譯器,但我使用了Object.assign()方法。 – hellomoto
是的,Babel只是將'... someObject'轉換爲'Object.assign({},someObject)',所以沒關係。如果你厭倦了使用對象擴展,尤其是嵌套數據,我有一個很多不可變更新工具庫的列表,在https://github.com/markerikson/redux-ecosystem-links/blob/master/immutable-data .MD。 dot-prop-immutable庫看起來不錯,但有很多選項可供選擇。 – markerikson