52 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-01-23 20:04:12 +01:00
import { takeLatest } from 'redux-saga';
import { put } from 'redux-saga/effects';
import {
2017-01-26 18:53:52 +01:00
loadedRecord
2017-01-23 20:04:12 +01:00
} from './actions';
import {
2017-01-26 18:53:52 +01:00
LOAD_RECORDS
2017-01-23 20:04:12 +01:00
} from './constants';
export function* getRecords() {
const fakeData = [{
id: 1,
2017-01-23 20:04:12 +01:00
title: 'Roger Federer has won the first set.',
message: 'Try to do better than that man and you will be a winner.'
}, {
id: 2,
2017-01-23 20:04:12 +01:00
title: 'Lewis Hamilton is on fire.',
message: 'Did you ever seen someone like that guy?'
}, {
id: 3,
2017-01-23 20:04:12 +01:00
title: 'Elon Musk is awesome!',
message: 'Space X, Paypal, Tesla, & cie.'
}];
2017-01-28 18:11:54 +01:00
try {
const opts = {
method: 'GET',
mode: 'cors',
cache: 'default'
};
const response = yield fetch('http://localhost:1337/admin/config/models', opts);
const data = yield response.json();
yield put(loadedRecord(fakeData, data));
} catch (err) {
console.error(err);
}
2017-01-23 20:04:12 +01:00
}
// Individual exports for testing
export function* defaultSaga() {
2017-01-23 20:04:12 +01:00
yield takeLatest(LOAD_RECORDS, getRecords);
}
// All sagas to be loaded
export default [
defaultSaga,
];