2021년 12월 27일 https://junilhwang.github.io/TIL/Javascript/Design/Vanilla-JS-Store/#_5-flux-pattern

앞서 Observer Pattern에 대해 알아본 것 처럼, Vuex나 Redux에서 사용되는 Flux Pattern에 대해서 알아보자.

https://junilhwang.github.io/TIL/assets/img/9.c657b6ab.png

Vue는 이를 조금 변형하여 다음과 같은 형태로 사용한다.

https://junilhwang.github.io/TIL/assets/img/10.8466eecc.png

6. Vuex 같은 Store 만들기

일단 vuex를 만들기 이전에, vuex가 어떤 interface를 가지고 있는지 살펴보자. **공식문서 (opens new window)**에서 보여주고 있는 코드는 다음과 같다.

const store = new Vuex.Store({
  state: {
    count: 0 
  },
  mutations: {
    increment (state) {
      state.count++
    }
  }
});

state가 있고, state를 변경시킬 수 있는 mutations가 존재하는 것을 확인할 수 있다.

그리고 이렇게 선언된 store는 다음과 같이 사용된다.