import invariant from 'invariant'
import isPlainObject from 'is-plain-object'
function validateModel(model, modelList) {
const {namespace, reducers = {}, effects = {}} = model
//必须有namespace
invariant(namespace, `[teeMo.model] 应该定义 namespace`)
//必须是string类型
invariant(typeof namespace === 'string', `[teeMo.model] namespace必须是string类型,当前namespace的类型是 [${typeof model.namespace}]`)
//必须唯一
invariant(!modelList.some(m => namespace === m.namespace), `[teeMo.model] namespace必须唯一`)
//reducers必须是一个普通的javaScript对象
invariant(isPlainObject(reducers), `[teeMo.model] reducers必须是一个普通的javaScript对象,当前的reducer的类型是 [${typeof reducers}]`)
//effects必须是一个普通的javaScript对象
invariant(isPlainObject(effects), `[teeMo.model] effects必须是一个普通的javaScript对象,当前的effect的类型是 [${typeof effects}]`)
}
export {
validateModel
} |