dva-model-combo

0.1.1 • Public • Published

dva-model-combo

npm package Dependency Status

Utility method to combo dva model.

Installation

npm install --save dva-model-combo

Usage

import modelCombo from 'dva-model-combo';

const tableClass = {
  reducers: {
    querySuccess(state, { payload: pagination }) {
      return { 
        ...state, 
        pagination: {
          ...state.pagination,
          ...pagination,
        }
      }
    },
  },
}

const routeModel = modelCombo('media_search', {
  domain: 'header',
  state: {
    menu: [],
    extend: true,
  },
}, {
  domain: 'body',
  state: {
    data: [],
    pagination: {}
  },
  mixin: tableClass,
})

=>

{
    "namespace":
    "media_search",
    "state":
    {
        "header":
        {
            "menu": [],
            "extend": true,
        },
        "body":
        {
            "data": [],
            "pagination": {},
        }
    },
    "subscriptions": {},
    "effects": {},
    "reducers": {
        'body$querySuccess': (state, { payload: pagination }) => {
            return {
                ...state,
                pagination: {
                    ...state.pagination,
                    ...pagination,
                },
            }
        },
    },
}

API

modelCombo(namespace, ...domains) => Model

Behaviour:

  • The mixin use By dva-model-extend thx~
  • model[subscriptions|effects|reducers] use the domain as its prefix and use $ as a separator.
  • model[state] use the domain as its property name.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i dva-model-combo

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • yangbin1994