src/index.js
function createRootReducer (model, name) {
  const handlers = {}
  const initialState = model.state
  // auto-generated reducers
  if (isNotNullObject(initialState)) {
    for (const key of Object.keys(initialState)) {
      handlers[addSetPrefix(name)(key)] = (state, action) => includeKey(action, 'payload') ? { ...state, [key]: action.payload } : state
    }
  }
  // reducer for updating multiple field of the state in one action
  // or replace the state directly
  handlers[addPrefix(name)('merge')] = (state, action) => {
    if (!includeKey(action, 'payload')) {
      return state
    }
    const payload = action.payload
    if (isNotArrayObject(state)) {
      // if (includeNewKeys(state, payload)) {
      //   return pureMerge(state, payload)
      // } else {
      //   return { ...state, ...payload }
      // }
      return pureMerge(state, payload)
    } else {
      return payload
    }
  }
  // user defined reducers
  for (const r of Object.keys(model.reducers || {})) {
    const reducer = model.reducers[r]
    let finalReducer
    if (typeof reducer === 'function') {
      finalReducer = (state, action) => reducer(state, action)
    } else {
      finalReducer = (state) => state
    }
    // notice the reducer override occurs here
    handlers[addPrefix(name)(r)] = finalReducer
  }
  return (state = initialState, action) => (handlers[action.type] ? handlers[action.type](state, action) : state)
}
function createRootReducer (model, name) {
  const handlers = {}
  const initialState = model.state
  // auto-generated reducers
  if (isNotNullObject(initialState)) {
    for (const key of Object.keys(initialState)) {
      handlers[addSetPrefix(name)(key)] = (state, action) => includeKey(action, 'payload') ? { ...state, [key]: action.payload } : state
    }
  }
  // reducer for updating multiple field of the state in one action
  // or replace the state directly
  handlers[addPrefix(name)('merge')] = (state, action) => {
    if (!includeKey(action, 'payload')) {
      return state
    }
    const payload = action.payload
    if (isNotArrayObject(state)) {
      // if (includeNewKeys(state, payload)) {
      //   return pureMerge(state, payload)
      // } else {
      //   return { ...state, ...payload }
      // }
      return pureMerge(state, payload)
    } else {
      return payload
    }
  }
  // user defined reducers
  for (const r of Object.keys(model.reducers || {})) {
    const reducer = model.reducers[r]
    let finalReducer
    if (typeof reducer === 'function') {
      finalReducer = (state, action) => reducer(state, action)
    } else {
      finalReducer = (state) => state
    }
    // notice the reducer override occurs here
    handlers[addPrefix(name)(r)] = finalReducer
  }
  return (state = initialState, action) => (handlers[action.type] ? handlers[action.type](state, action) : state)
}
function createRootReducer ( model , name ) { const handlers = { } const initialState = model . state // auto-generated reducers if ( isNotNullObject ( initialState ) ) { for ( const key of Object . keys ( initialState ) ) { handlers [ addSetPrefix ( name ) ( key ) ] = ( state , action ) => includeKey ( action , 'payload' ) ? { ... state , [ key ] : action . payload } : state } } // reducer for updating multiple field of the state in one action // or replace the state directly handlers [ addPrefix ( name ) ( 'merge' ) ] = ( state , action ) => { if ( ! includeKey ( action , 'payload' ) ) { return state } const payload = action . payload if ( isNotArrayObject ( state ) ) { // if (includeNewKeys(state, payload)) { //   return pureMerge(state, payload) // } else { //   return { ...state, ...payload } // } return pureMerge ( state , payload ) } else { return payload } } // user defined reducers for ( const r of Object . keys ( model . reducers || { } ) ) { const reducer = model . reducers [ r ] let finalReducer if ( typeof reducer === 'function' ) { finalReducer = ( state , action ) => reducer ( state , action ) } else { finalReducer = ( state ) => state } // notice the reducer override occurs here handlers [ addPrefix ( name ) ( r ) ] = finalReducer } return ( state = initialState , action ) => ( handlers [ action . type ] ? handlers [ action . type ] ( state , action ) : state ) }
Create a root reducer based on model state and model reducers

If you have a model like the below
{
namespace: 'form',
state: {
loading: false,
password: ''
}
}

then sirius will generate a reducer for each state field following a preset rule:

for state loading : form/setLoading
for state password : form/setPassword

And a reducer receiving action whose type is '<namespace>/merge' (in the scenario above is 'form/merge')
will be generated.
If state is an Object (not Array, not null), action payload must be a 'sub-object' of the state
which means all the fields of payload can be also found in the state. the 'merge' reducer will
do a 'merge-like' action to the state just like Object Spreading.

If the state is not an Object, reducer replace the state with payload directly.

@param {Object} model  model
@param {String} name  model namespace
@returns {Function}  combined reducer for the model
Create a root reducer based on model state and model reducers