Git Product home page Git Product logo

redux-saga-in-chinese's Issues

副作用 (side effects)

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 结束
}

delay 方法引用错误

文章中

import { delay } from 'redux-saga'

正确

import { delay } from "redux-saga/effects"

更新文档至最新的 redux-saga 版本

贡献指南:

  1. fork redux-saga-in-chinese & git clone
  2. master 基础上创建一个分支,比如 sync-introduction-beginner-tutorial
  3. npm i && npm run watch
  4. issues 列表查找任务,回复认领
  5. 找到具体的章节,如 docs/introduction/BeginnerTutorial.md
  6. 翻译它,参考 ETC 翻译规范
  7. 完成后,发 PR 到 0.11.0 分支
  8. 如果一切 OK,PR 会尽快被合并

redux-saga v1.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对我们编写代码的方式有微妙的影响(好处)

翻译志愿者招募

如果想参与翻译某个章节,直接回复此 issue 即可,比如:

认领 高级 - 组合 Sagas

翻译流程参考 ETC 翻译规范

先查看 翻译进度,后面有 ing 标志,说明此章节已被认领。

高级-同时执行多个任务,应当为yield all([]), 缺少了all()函数调用

如题所示,在 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作“异步”理解并不是准确的,也可能误导使用者不在自己的应用中将有副作用的代码完全隔离,最终变成不伦不类的模型

redux-saga-beginner-tutorial示例代码与原文不同

目前文档中的代码:

// ...
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

文档同步(v1.0.0-beta)

现在的文档版本过于老旧(基于 v0.9.5),已经无法跟上社区的步伐,现启动同步至官方最新文档的工作。

由于个人时间有限,现招募志愿者一起来完成这项工作。欢迎认领翻译任务,为 redux-saga 中文社区作出贡献,翻译工作完成后,所有贡献者将会列在本项目首页,还等什么!

贡献

志愿者必须具备一定的英语水平。如果你想成为一个志愿者,在本 issue 中留言如 认领 advanced/Channels.md,然后我会更新本 issue,在你认领的任务标注志愿者名字并@。同时招募审稿人(reviewer),目前审稿人为 @superRaytin

工作步骤:

  1. fork redux-saga-in-chinese & git clone
  2. redux-saga-in-chinese:1.0.0 基础上创建一个分支,比如 sync-advanced-channels
  3. npm i && npm run watch
  4. 翻译认领的任务,参考 ETC 翻译规范
  5. 翻译完成后,发 PR 到 redux-saga-in-chinese:1.0.0 分支
  6. 如果一切 OK,PR 会尽快被合并

TODOs

advanced

api

basics

introduction

recipes

已经完成的任务,可以到 1.0.0 分支查看

启动 saga 代码错误

按照文章的代码,启动 saga 无效,查看了官方英文原版,发现正确的代码应该如下

import rootSaga from './sagas'

const sagaMiddleware = createSagaMiddleware()

const store = createStore(reducer, applyMiddleware(sagaMiddleware))

sagaMiddleware.run(rootSaga)

Beginner Tutorial 部分代码与官方文档不一致

官方文档中的示例代码
// ...
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,作为新手,回去看原文才明白哪里错了,还望更新。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.