import lodash from 'lodash'

const mutations = {
  UPDATE_LAYOUT: (state, provider) => {
    provider.moduleList = [...provider.moduleList] // 防止部分不触发更新

    state.layoutData = provider
  },
  UPDATE_COMPONENT: (state, provider) => {
    state.layoutData.moduleList = state.layoutData.moduleList.map(item => {
      if (item.name === provider.name) {
        return provider
      }
      return item
    })
    // 防止部分不触发更新
    // 还要刷新state.layoutData的地址,因为其他地方有依赖state.layoutData进行响应
    state.layoutData = lodash.cloneDeep(state.layoutData)
  },

  //  tabar相关的mutations
  // 更新关于tabbar模板列表的数据
  SAVE_TAB_MUDULE_LIST: (state, provider) => {
    state.tabbarData.tabList = lodash.cloneDeep(provider)
  },
  SAVE_TAB_MUDULE_EDITOR: (state, provider) => {
    state.tabbarData.tabList = lodash.cloneDeep(provider)
  }
}

export default mutations
