Русский перевод Redux Saga
  • Главная страница
  • Содержание
    • Главная страница
    • 1. Введение
      • 1.1 Руководство для начинающих
      • 1.2 Предпосылки Saga
    • 2. Основные концепции
      • 2.1. Использование хелперов Saga
      • 2.2 Декларативные эффекты
      • 2.3 Отправка действий
      • 2.4 Обработка ошибок
      • 2.5 Распространёная абстрация: Эффект
    • 3. Продвинутые концепции
      • 3.1 Получение будущих действий
      • 3.2 Неблокирующие вызвы
      • 3.3 Выполнение задач параллельно
      • 3.4 Выполнение гонки между несколькими эффектами
      • 3.5 Последовательность Sagas с использованием yield*
      • 3.6 Композиция Sagas
      • 3.7 Отмена задач
      • 3.8 Модель форвка redux-saga
      • 3.9 Общие паттерны параллелизма
      • 3.10 Примеры тестирования Sagas
      • 3.11 Подключение Sagas к внешнему входу/выходу
      • 3.12 Использование каналов
      • 3.13 Шаблоны корневой саги
    • 4. Рецепты
    • 5. Внешние ресурсы
    • 6. Исправление проблем
    • 7. Глоссарий
    • 8. Справочник API
Powered by GitBook
On this page
  • Effect
  • Task
  • Blocking/Non-blocking call
  • Watcher/Worker
  1. Содержание

7. Глоссарий

This is a glossary of the core terms in Redux Saga.

Effect

An effect is a plain JavaScript Object containing some instructions to be executed by the saga middleware.

You create effects using factory functions provided by the redux-saga library. For example you use call(myfunc, 'arg1', 'arg2') to instruct the middleware to invoke myfunc('arg1', 'arg2') and return the result back to the Generator that yielded the effect

Task

A task is like a process running in background. In a redux-saga based application there can be multiple tasks running in parallel. You create tasks by using the fork function

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

function* saga() {
  ...
  const task = yield fork(otherSaga, ...args)
  ...
}

Blocking/Non-blocking call

A Blocking call means that the Saga yielded an Effect and will wait for the outcome of its execution before resuming to the next instruction inside the yielding Generator.

A Non-blocking call means that the Saga will resume immediately after yielding the Effect.

For example

import {call, cancel, join, take, put} from "redux-saga/effects"

function* saga() {
  yield take(ACTION)              // Blocking: will wait for the action
  yield call(ApiFn, ...args)      // Blocking: will wait for ApiFn (If ApiFn returns a Promise)
  yield call(otherSaga, ...args)  // Blocking: will wait for otherSaga to terminate

  yield put(...)                   // Non-Blocking: will dispatch within internal scheduler

  const task = yield fork(otherSaga, ...args)  // Non-blocking: will not wait for otherSaga
  yield cancel(task)                           // Non-blocking: will resume immediately
  // or
  yield join(task)                              // Blocking: will wait for the task to terminate
}

Watcher/Worker

refers to a way of organizing the control flow using two separate Sagas

  • The watcher: will watch for dispatched actions and fork a worker on every action

  • The worker: will handle the action and terminate

example

function* watcher() {
  while (true) {
    const action = yield take(ACTION)
    yield fork(worker, action.payload)
  }
}

function* worker(payload) {
  // ... do some stuff
}
Previous6. Исправление проблемNext8. Справочник API

Last updated 6 years ago