Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Created November 17, 2018 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save productioncoder/f254711b4f0d336670e9aa49c2f12b1f to your computer and use it in GitHub Desktop.
Save productioncoder/f254711b4f0d336670e9aa49c2f12b1f to your computer and use it in GitHub Desktop.
Youtube in React: comment thread watcher and worker saga
import {fork, take} from 'redux-saga/effects';
import {REQUEST} from '../actions';
import * as commentActions from '../actions/comment'
import * as api from '../api/youtube-api';
import {fetchEntity} from './index';
export function* fetchCommentThread(videoId, nextPageToken) {
const request = api.buildCommentThreadRequest.bind(null, videoId, nextPageToken);
yield fetchEntity(request, commentActions.thread, videoId);
}
export function* watchCommentThread() {
while(true) {
const {videoId, nextPageToken} = yield take(commentActions.COMMENT_THREAD[REQUEST]);
yield fork(fetchCommentThread, videoId, nextPageToken);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment