Hier ist mein Verständnis, in Bezug auf Redox ein Reduzierer ist eine Funktion, die zwei Argumente akzeptiert (Zustand, Aktion).
1. state represents the current state of the application in store
2. action represents the action that triggered
Redux geht davon aus, dass die Reduzierungen den aktuellen Zustand akzeptiert und den Staat nicht mutieren, sondern gibt den neuen Zustand, auf dem Aktionstyp abhängig. Wenn es haftet und den Zustand nicht mutiert, dann ist es ein reiner Minderer.
/********************** Beispiel eines reinen Reduzierers ****************** ***********/
var initialState = {counter:0};
function counterReducer(state = initialState, action){
if (action.type === 'INCREMENT'){
// returns a new state incrementing a counter
return {counter:state.counter + 1};
}
else if (action.type === 'DECREMENT'){
// return a new state decrementing a counter
return {counter:state.counter - 1};
}
// returns the state as is
return state;
}
die obige Funktion hat keine Nebenwirkungen, wenn sie mit dem gleichen Satz von Argumenten aufgerufen wird, ist es immer die gleiche Leistung zurückgibt.
/********************* Beispiel eines unreinen Minderer ******************* ********/
var initialState = {counter:0};
function counterReducer(state = initialState, action){
if (action.type === 'INCREMENT'){
// modifies state by mutating or incrementing the counter in state
state.counter++;
}
else if (action.type === 'DECREMENT'){
// modifies state by mutating or decrementing the counter in state
state.counter--;
}
// returns the state
return state;
}
ein Reducer ist eine Funktion. eine bestimmte Art von einem, aber nur eine Funktion. gleiche Sache. Eine Rose mit einem anderen Namen ... – dandavis
Reducer ist eine Funktion, das ist nur ein spezifischer Name. –