All files / src validation.js

100% Statements 7/7
100% Branches 2/2
100% Functions 2/2
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28          13x     13x     12x     11x     10x     9x              
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
}