Created
February 12, 2016 17:31
-
-
Save tomkis/951fd36d485243f5ca71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import api from './path/to/api' | |
import { take } from 'redux-saga' | |
function* watchSave() { | |
while(true) { | |
const { data } = yield take('SAVE_DATA'); | |
// Just naive example that callbacks do not propagate yield* | |
yield* data | |
.forEach(function*(record) { | |
yield api.save(record) | |
}); // this may be some non-trivial non-generator friendly function | |
} | |
} |
yield data.forEach(function*(record) {
yield api.save(record)
});
why not using map instead???
@slorber we've been discussing this with @yelouafi on twitter. You guys probably missed my pain point and it's the fact that you simply can't use HoF with generators. Of course, I am aware that it can be mapped over but this is a trivial use case - there'r many use cases when you simply have a lot of code implemented which heavily relies on callbacks - and this can't be used because callbacks do not propagate yield*
automatically.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure to understand why do you have to dispatch an observable to the store
Shouldn't you rather listen to the observable from the outside and dispatch incoming occurrences to the store