Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

## Redux-alita使用说明 #1

Open
chenkangyang opened this issue Jun 9, 2019 · 0 comments
Open

## Redux-alita使用说明 #1

chenkangyang opened this issue Jun 9, 2019 · 0 comments

Comments

@chenkangyang
Copy link
Owner

Redux-alita使用说明

看了一下redux-alita的实现, 稍微写一下自己的理解, 有错误请指正! @SiroSong @hypo1986
使用React-Redux针对此项目进行了封装,

提供4个功能:
{AlitaProvider, connectAlita, setAlitaState, setConfig}

AlitaProvider

  1. 使用 redux-thunk 作为异步action中间件, 生成唯一的一个容器 store,
  2. 提供一个包裹在根组件外面的Provider组件, 使所有的子组件都能拿到 store, 它的原理是React组件的context属性

connectAlita(state)

  1. 使用connect方法, 从 "UI组件"(App组件) 生成 "容器组件"
  2. 传入参数state, 使用mapStateToProps负责输入逻辑, 即将state映射到 "UI组件"的参数(props), 引起UI组件的更新
  3. 使用mapDispatchToProps负责输出逻辑, 即将用户对 "UI组件"的操作映射成 Action, 传给Store存储, 引起state的更新

setAlitaState(Object)

    Object.funcName: 请求接口函数名称
    Object.stateName: category
    Object.data: data
    Object.params: 请求接口的参数
    之后 dispatch 执行一个 Action, 表示 state 要发生变化

setConfig (apis)

传入所有的接口, 存入funcs, 以便使用funcs[funcName](params)执行接口函数

Originally posted by @chenkangyang in yezihaohao/react-admin#12 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant