8000 effects · Issue #5 · herculesJS/herculex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

effects #5

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

Open
blizzardzheng opened this issue Oct 20, 2018 · 0 comments
Open

effects #5

blizzardzheng opened this issue Oct 20, 2018 · 0 comments
Assignees

Comments

@blizzardzheng
Copy link
Contributor
blizzardzheng commented Oct 20, 2018

Principle

说到 effects 必须要提两个知名项目:elmJS 与 redux-saga。
在仔细阅读两个项目的 Architecture 与部分源码后打算引入一些简单的 helper 给 herculex。
effects 目的很简单能更好的去处理函数副作用,提供了一些事务级函数 wrapper 助手。当然这套如果照搬到 herculex 显然是不合理的。因为 herculex 的定位是轻量以及入门门槛低,于是我们需要对 effects 的概念做一些隐藏和删减,并且放弃 generator,最多使用 async 与await 申明式配置副作用。只用最简单的 api 实现部分对异步事件管控即可, 并且用或不用非强制。对效果的描述我们已有 getIn,setIn,dispatch和commit,需要增加的只是一些控制流,如 takeEvery takeLatest。以及增加对纯副作用的监控类似 mobx里的 autorun

api should be

actions: {
   fetchData({commit}) {
	
	},
	getUserInfo({commit, dispatch}) {
       // 默认dispatch就是takeEvery操作,等同于 thunk pattern
		await dispatch.every('fetchUserInfo') // 允许同时启动多个实例, 我们可以fetchData在仍有一个或多个fetchData尚未终止的先前任务的同时开始新任务
		await dispatch.latest('fetchUserInfo') // 只允许一个fetchData任务在任何时刻运行		
	},
},

可测试性论证(待完善)

@blizzardzheng blizzardzheng self-assigned this Oct 20, 2018
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
0