// acc accumulator 누적자
[1,2,3,4,5].reduce((prev, v) =>  prev + v, 0)

acc value 
   0     1    => 1
   1     2    => 3
   3    3   => 6
   6    4   => 10
   10   5   => 15

Quick Start | Redux Toolkit

// { value: 0 }  {type:"counter/increment"}
function reducer(state, action){
    if(action.type === 'counter/decrement'){
        return { value: state.value - 1 }
    }
    if(action.type === 'counter/increment'){
        return { value: state.value + 1 }
    }
    if(action.type === 'counter/incrementByAmount'){
        return { value: state.value + action.payload.amount }
    }
}
// a,b                   => a+b
//(state, action) => newState

[
  {type:"counter/increment"},
  {type:"counter/increment"},
  {type:"counter/decrement"},
  {type:"counter/increment"},
  {type:"counter/incrementByAmount", payload: { amount: 3 } }
].reduce(reducer, { value: 0 })

/*
state            action
{ value: 0 }  {type:"counter/increment"} => { value: 1 }
{ value: 1 }  {type:"counter/increment"} => { value: 2 }
{ value: 2 }  {type:"counter/decrement"} => { value: 1 }
{ value: 1 }  {type:"counter/increment"} => { value: 2 }
{ value: 2 }  {type:"counter/incrementByAmount", payload: { amount: 3 } }  => { value: 5 }
*/

action

actionCreator

action ⇒ reducer

store

redux

이벤트 소싱 + 직렬화 가능한

첫째 상태를 변경한 history를 남긴다.

history를 토대로 언제든지 상태를 복원할 수 있고...

history를 저장해버릴 수도 있다!

에러가 나면 개발자에게 보내줄 수도 있다

JSON.stringify

Date ⇒ string ⇒ Date

File