import {OtherState} from '@/types/views/other.interface';
import {GetterTree, MutationTree, ActionTree} from 'vuex';

const state: OtherState = {
    author: '三毛'
};

// 强制使用getter获取state
const getters: GetterTree<OtherState, any> = {
    author: (state: OtherState) => state.author
};

// 更改state
const mutations: MutationTree<OtherState> = {
    // 更新state都用该方法
    UPDATE_STATE(state: OtherState, data: OtherState) {
        for (const key in data) {
            if (!data.hasOwnProperty(key)) {
                return;
            }
            // @ts-ignore
            state[key] = data[key];
        }
    }
};

const actions: ActionTree<OtherState, any> = {
    UPDATE_STATE_ASYN({commit, state: OtherState}, data: OtherState) {
        commit('UPDATE_STATE', data);
    },
    // GET_DATA_ASYN({ commit, state: LoginState }) {
    //   Other.getData()
    // }
};

export default {
    state,
    getters,
    mutations,
    actions
};

