Skip to content

Instantly share code, notes, and snippets.

@skellock
Created June 27, 2016 12:55
Show Gist options
  • Save skellock/78219bc704250bf6a1b1992d995f9130 to your computer and use it in GitHub Desktop.
Save skellock/78219bc704250bf6a1b1992d995f9130 to your computer and use it in GitHub Desktop.
import { put, call, select } from 'redux-saga/effects'
export function acquireDataFromSomewhere (numberOfThings) {
return new Promise((resolve, reject) => {
resolve(`here are ${numberOfThings} things`)
})
}
// Fires when we see TIME_TO_SHINE come through.
// Its pretty random what we do here.
// The point is to really show how tests work.
export default function * (action) {
// step 1
yield put({ type: 'INCREMENT' })
// step 2
const state = yield select()
const currentCounterValue = state.counter.value
// step 3
const data = yield call(
acquireDataFromSomewhere,
currentCounterValue
)
// step 4
yield put({type: 'SAVE_DATA', randomPieceOfData: data})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment