import { observable } from 'mobx'
interface ClassifyData {
    id: number,
    name: string,//分类名称
    workDirection: number,//频道
}

export interface ClassifyStore {
    /**分类id*/
    categoryId: { id: number, name: string },//分类ID
    workDirection: 0 | 1,
    bookList: any,
    /**分类列表*/
    classifyData: ClassifyData[],
    setData: (data: { [key: string]: any }) => void
}
/**
 * 分类独有参数
 * */
const classifyStore: ClassifyStore = observable({
    categoryId: { id: 0, name: "" },
    workDirection: 0,
    bookList: [],
    classifyData: [],
    setData(data: { [key: string]: any }) {
        if (data) {
            Object.keys(data).forEach(key => {
                //数据不同才存放
                if (JSON.stringify(this[key]) !== JSON.stringify(data[key])) {
                    this[key] = data[key]
                }
            })
        }
    },
})

export default classifyStore