Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pitch - Lidando com Efeitos Colaterais com Redu...

Filipe Costa
February 11, 2017

Pitch - Lidando com Efeitos Colaterais com Redux Saga

Pitch para palestrar no CEJS 2017.

Filipe Costa

February 11, 2017
Tweet

More Decks by Filipe Costa

Other Decks in Programming

Transcript

  1. "Evolui ideias do Flux, mas evita suas complexidades pegando dicas

    do Elm" — github.com/reactjs/redux Redux
  2. Redux UI Middleware Reducer Store Action dispatched (currentState, action) =>

    newState New State Action forwarded Action dispatched
  3. ES6

  4. function* foo(x) { const y = 2 * (yield (x

    + 1)); const z = yield (y / 3); return (x + y + z); } var it = foo(5); // note: not sending anything into `next()` here console.log(it.next()); // { value:6, done:false } console.log(it.next(12)); // { value:8, done:false } console.log(it.next(13)); // { value:42, done:true } https://davidwalsh.name/es6-generators
  5. import { call, put } from 'redux-saga/effects'; export function* fetchData(action)

    { try { const data = yield call(Api.fetchUser, action.payload.url); yield put({type: "FETCH_SUCCEEDED", data}); } catch (error) { yield put({type: "FETCH_FAILED", error}); } } function* watchFetchData() { yield takeEvery('FETCH_REQUESTED', fetchData); } https://redux-saga.github.io/redux-saga/docs/basics/UsingSagaHelpers.html
  6. import { takeEvery } from 'redux-saga'; // FETCH_USERS function* fetchUsers(action)

    { ... } // CREATE_USER function* createUser(action) { ... } // use them in parallel export default function* rootSaga() { yield takeEvery('FETCH_USERS', fetchUsers); yield takeEvery('CREATE_USER', createUser); } https://redux-saga.github.io/redux-saga/docs/basics/UsingSagaHelpers.html