superraytin / redux-saga-in-chinese Goto Github PK
View Code? Open in Web Editor NEWRedux-saga 中文文档
Home Page: https://redux-saga-in-chinese.js.org/
Redux-saga 中文文档
Home Page: https://redux-saga-in-chinese.js.org/
在 https://github.com/superRaytin/redux-saga-in-chinese/blob/master/README.md 提到:
redux-saga 是一个用于管理 Redux 应用异步操作(Side Effects。译注:直译成 “副作用” 不太通顺,所以这里译为 “异步操作” 更好理解)的中间件(又称异步 action)。 redux-saga 通过创建 Sagas 将所有的异步操作逻辑收集在一个地方集中处理,可以用来代替 redux-thunk 中间件。
關於副作用解釋成異步操作
是錯的,side effects 可以是同步的。
Side effects 本身就是指「副作用」,就是無法從 return 回傳值中可觀察到的改變外部行為。這是函數式編程的基礎。
跟着中文网的代码写出来都跑不起来。。。
function* saga() {
yield take(ACTION) // 阻塞: 将等待 action
yield call(ApiFn, ...args) // 阻塞: 将等待 ApiFn (如果 ApiFn 返回一个 Promise 的话)
yield call(otherSaga, ...args) // 阻塞: 将等待 otherSaga 结束
yield put(...) // 阻塞: 将同步发起 action (使用 Promise.then)
const task = yield fork(otherSaga, ...args) // 非阻塞: 将不会等待 otherSaga
yield cancel(task) // 非阻塞: 将立即恢复执行
// or
yield join(task) // 阻塞: 将等待 task 结束
}
这句话:
yield put(...) // 阻塞: 将同步发起 action (使用 Promise.then)
但是我看最新的Glossary.md已经翻译过来了
function* saga() {
yield take(ACTION) // 阻塞: 将等待 action
yield call(ApiFn, ...args) // 阻塞: 将等待 ApiFn (如果 ApiFn 返回一个 Promise 的话)
yield call(otherSaga, ...args) // 阻塞: 将等待 otherSaga 结束
yield put(...) // 非阻塞: 将同步发起 action (使用 Promise.then)
yield put.resolve(...) // 阻塞
const task = yield fork(otherSaga, ...args) // 非阻塞: 将不会等待 otherSaga
yield cancel(task) // 非阻塞: 将立即恢复执行
// or
yield join(task) // 阻塞: 将等待 task 结束
}
文章中
import { delay } from 'redux-saga'
正确
import { delay } from "redux-saga/effects"
Glossary.html line 38
yied put(...) // 阻塞: 将同步发起 action (使用 Promise.then)
should be yield
贡献指南:
git clone
master
基础上创建一个分支,比如 sync-introduction-beginner-tutorial
npm i && npm run watch
docs/introduction/BeginnerTutorial.md
0.11.0
分支redux-saga v1.0 已经正式发布了,希望中文文档也能尽快更新。相比于 1.0.0-beta,1.0 的更新内容应该不会太多。
文件:监听未来的action
官方文档: Using take has a subtle impact on how we write our code
中文文档翻译:使用 take 组织代码有一个小问题
当前的语境应该翻译为:使用take对我们编写代码的方式有微妙的影响(好处)
如题所示,在 https://redux-saga-in-chinese.js.org/docs/advanced/RunningTasksInParallel.html 中出现了这个问题,虽然此github源中的文档内容和英文原版没有出入,都是用的yield all([]), 但是在html版本的文档中并没有得到同步。
中文文档: https://redux-saga-in-chinese.js.org/docs/advanced/RunningTasksInParallel.html
此github源: https://github.com/superRaytin/redux-saga-in-chinese/tree/master/docs/advanced/RunningTasksInParallel.md
redux-saga 是一个用于管理 Redux 应用异步操作(Side Effects。译注:直译成 “副作用” 不太通顺,所以这里译为 “异步操作” 更好理解)的中间件(又称异步 action)。
我认为此处的Side Effects应该直译为“副作用”,saga的理念并不是维护和管理异步,而是将所有“非纯(impure)”的东西从源码和逻辑两个层面上独立出来,放在一个隔离的区域内单独管理
举一个最简单的案例,document.cookie
的操作很显然是同步的,但是当使用saga时,你并不会在一个action creator中直接写setCookie('myCookie', value)
,而是会使用dispatch({type: 'SET_COOKIE', payload: ...})
交给saga进行处理,同样getCookie
也会使用类似的方案,这就是saga本身的概念模型
因此,在中文翻译中将Side Effects作“异步”理解并不是准确的,也可能误导使用者不在自己的应用中将有副作用的代码完全隔离,最终变成不伦不类的模型
并发执行 请加个all
Thumbs up for your work! 👍
I can help with small sections.
I will translate chapter 3.3.
hello sagas一章中修改main.js部分的代码在html中有问题:
https://redux-saga-in-chinese.js.org/docs/introduction/BeginnerTutorial.html
目前文档中的代码:
// ...
import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
//...
import { helloSaga } from './sagas'
const store = createStore(
reducer,
applyMiddleware(createSagaMiddleware(helloSaga))
)
// rest unchanged
应该更新为:
// ...
import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
// ...
import { helloSaga } from './sagas'
const sagaMiddleware = createSagaMiddleware()
const store = createStore(
reducer,
applyMiddleware(sagaMiddleware)
)
sagaMiddleware.run(helloSaga)
const action = type => store.dispatch({type})
// rest unchanged
现在的文档版本过于老旧(基于 v0.9.5),已经无法跟上社区的步伐,现启动同步至官方最新文档的工作。
由于个人时间有限,现招募志愿者一起来完成这项工作。欢迎认领翻译任务,为 redux-saga 中文社区作出贡献,翻译工作完成后,所有贡献者将会列在本项目首页,还等什么!
志愿者必须具备一定的英语水平。如果你想成为一个志愿者,在本 issue 中留言如 认领 advanced/Channels.md
,然后我会更新本 issue,在你认领的任务标注志愿者名字并@。同时招募审稿人(reviewer),目前审稿人为 @superRaytin
工作步骤:
redux-saga-in-chinese:1.0.0
基础上创建一个分支,比如 sync-advanced-channels
npm i && npm run watch
redux-saga-in-chinese:1.0.0
分支advanced
api
basics
introduction
recipes
已经完成的任务,可以到 1.0.0 分支查看
规则借鉴自 redux-in-chinese
阶段性同步,回复即可认领。
原文链接:
按照文章的代码,启动 saga 无效,查看了官方英文原版,发现正确的代码应该如下
import rootSaga from './sagas'
const sagaMiddleware = createSagaMiddleware()
const store = createStore(reducer, applyMiddleware(sagaMiddleware))
sagaMiddleware.run(rootSaga)
阶段性同步,回复即可认领。
原文链接:
官方文档中的示例代码
// ...
import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
// ...
import { helloSaga } from './sagas'
const sagaMiddleware = createSagaMiddleware()
const store = createStore(
reducer,
applyMiddleware(sagaMiddleware)
)
sagaMiddleware.run(helloSaga)
const action = type => store.dispatch({type})
// rest unchanged
翻译中的示例代码
// ...
import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
//...
import { helloSaga } from './sagas'
const store = createStore(
reducer,
applyMiddleware(createSagaMiddleware(helloSaga))
)
// rest unchanged
使用翻译中的示例代码运行,并不能接入saga,作为新手,回去看原文才明白哪里错了,还望更新。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.