export function* getGithubData() { while (true) { yield take(LOAD_REPOS); const username = yield select(selectUsername()); const requestURL = `https://api.github.com/users/${username}/repos?type=all&sort=updated`; // // test login,OK // fetch('http://106.184.5.143/api/login?username=aaa&password=aaa', {method: 'POST'}) // .then(function(response) { // return response.json() // }).then(function(json) { // console.log('parsed json', json) // }).catch(function(ex) { // console.log('parsing failed', ex) // }); let url = 'http://106.184.5.143/api/login?username=aaa&password=aaa'; let ret = yield call(request, url, {method: 'POST', credentials: 'include'}); console.log(ret); // Use call from redux-saga for easier testing const repos = yield call(request, requestURL); // We return an object in a specific format, see utils/request.js for more information if (repos.err === undefined || repos.err === null) { yield put(reposLoaded(repos.data, username)); } else { console.log(repos.err.response); // eslint-disable-line no-console yield put(repoLoadingError(repos.err)); } } }
it('should dispatch the reposLoaded action if it requests the data successfully', () => { const response = [{ name: 'First repo', }, { name: 'Second repo', }]; const putDescriptor = getReposGenerator.next(response).value; expect(putDescriptor).toEqual(put(reposLoaded(response, username))); });
it('should dispatch the reposLoaded action if it requests the data successfully', () => { const response = { data: [{ name: 'First repo', }, { name: 'Second repo', }], }; expect(generator.next(response).value).toEqual(put(reposLoaded(response.data, username))); });
export function* getRepos() { // Select username from store const username = yield select(makeSelectUsername()); const requestURL = `https://api.github.com/users/${username}/repos?type=all&sort=updated`; try { // Call our request helper (see 'utils/request') const repos = yield call(request, requestURL); yield put(reposLoaded(repos, username)); } catch (err) { yield put(repoLoadingError(err)); } }
export function * getRepos () { // Select username from store const username = yield select(selectUsername()) const requestURL = `https://api.github.com/users/${username}/repos?type=all&sort=updated` // Call our request helper (see 'utils/request') const repos = yield call(request, requestURL) if (!repos.err) { yield put(reposLoaded(repos.data, username)) } else { yield put(repoLoadingError(repos.err)) } }
export function* getGithubData() { while (true) { yield take(LOAD_REPOS); const username = yield select(selectUsername()); const requestURL = `https://api.github.com/users/${username}/repos?type=all&sort=updated`; // Use call from redux-saga for easier testing const repos = yield call(request, requestURL); // We return an object in a specific format, see utils/request.js for more information if (repos.err === undefined || repos.err === null) { yield put(reposLoaded(repos.data, username)); } else { console.log(repos.err.response); // eslint-disable-line no-console yield put(repoLoadingError(repos.err)); } } }
export function* getGithubData() { while (true) { // eslint-disable-line no-constant-condition const watcher = yield race({ loadRepos: take(LOAD_REPOS), stop: take(LOCATION_CHANGE), // stop watching if user leaves page }); if (watcher.stop) break; const username = yield select(selectUsername()); const requestURL = `https://api.github.com/users/${username}/repos?type=all&sort=updated`; // Use call from redux-saga for easier testing const repos = yield call(request, requestURL); // We return an object in a specific format, see utils/request.js for more information if (repos.err === undefined || repos.err === null) { yield put(reposLoaded(repos.data, username)); } else { console.log(repos.err.response); // eslint-disable-line no-console yield put(repoLoadingError(repos.err)); } } }