Wenn ich meine Anwendung mit großem Schluck bauen, schluck hält mir einen Syntaxfehler geben:Syntaxfehler: unerwartetes Token bei der Implementierung Minderer in Redux
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;
Ich sehe einfach nicht, was hier falsch ist. Soweit ich das beurteilen kann, ist die Syntax hier richtig, um einen Reducer zu implementieren.
Das half, obwohl ich meinen transpiler nicht konfiguriert habe, stattdessen habe ich die 'Object.assign()' Methode verwendet. – hellomoto
Ja, Babel transpiliert einfach '... someObject' in' Object.assign ({}, someObject) ', das ist also in Ordnung. Wenn Sie es satt haben, Objektspreads zu verwenden, insbesondere für verschachtelte Daten, dann habe ich eine Liste mit vielen unveränderlichen Update-Utility-Bibliotheken unter https://github.com/markerikson/redux-ecosystem-links/blob/master/immutable-data .md. Die dot-prop-immutable lib scheint nett zu sein, aber es gibt viele Optionen zur Auswahl. – markerikson