/**
 * 简易版 store 实现
 */

import Vue from "vue";

/**
  * 构建 store, 所有 model 只能通过 initailStates 传递
  * @param {*} initailStates 
  */
export default function createStore(initailStates = {}) {
  const store = new Vue({
    data: { $$state: initailStates }
  })

  function getState(modelName) {
    return store._data.$$state[modelName]
  }

  function updateState(modelName, payload) {
    Vue.set(store._data.$$state, modelName, payload)
  }

  return {
    getState,
    updateState
  }
}
