import { inject, provide } from 'vue'

export default function createStore (initialState = {}) {
  let stateTree = { ...initialState }

  const setup = () => Object.keys(stateTree).map(k => provide(k, stateTree[k]))

  const addModel = (nm, mo) => {
    stateTree[nm] = mo
    provide(nm, mo)
  }

  const useModel = nm => inject(nm)

  const getState = nm => stateTree[nm]

  return {
    setup,
    addModel,
    useModel,
    getState,
  }
}
