3.0.5 • Published 4 years ago

edata-router-react-native v3.0.5

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

edata-router

文件结构

File tree:

index.jsx          # 主入口
actions/          # 接口动作(success/fail等)
├── index.js
├── products.js
└── users.js

主入口 index.jsx

import React from 'react'
import EdataRouter from 'edata-router'
import {actions1, actions2} from './actions'

const app = new EdataRouter({
  ajaxConfig: {
    headers: {},
    beforeRequest: (init)=>{},
    getResponse: (response)=>response,
    afterResponse: (response)=>{},
    errorHandler: (error)=>{}
  }
})

// 导入接口配置
app.model(actions1)

const actions2ResourceDef = {
  getList: {
    url: '/analysis/api/products/cat/:id',
    method: 'GET',
  }
}
// 可选传入资源定义
app.model(actions2, actions2ResourceDef)
... ...

// 挂载运行
const run = app.run()

// Use
run.getAPIProps()
run.hoc()

run.props  // 包含所有的API
run.model  // 全局model
run.routes  // 全局routes配置
run.store  // 内部Redux Store
run.options  // 启动options

接口定义 (actions/)

actions

每个模块都需导出如下结构:

module.exports = {
    name: 'products',  // 必填
    store: {},
    actions: {
        getList: {
          url: '/analysis/api/products/cat/:id',
          method: 'GET',
          param: () => ({  //支持对象(静态配置),函数(动态生成)
              workspaceCode: window.workspace
          }),
          callback: {
              start: function (store, init) {
              },
              success: function (store, result) {
              },
              fail: function (store, err) {
              }
          }
        },
        ... ...
    }
}

Header组件中,以下方法自动可用:

this.props.products.getList(
  query,
  {
    id: 123
  }
)

this.props.products.store   // store是action中定义的那个对象

this.props.model  // model是一个edata
3.0.5

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago