mirror of
https://github.com/strapi/strapi.git
synced 2025-08-15 12:18:38 +00:00
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
import { takeLatest } from 'redux-saga';
|
|
import { put } from 'redux-saga/effects';
|
|
|
|
import {
|
|
loadedRecord
|
|
} from './actions';
|
|
|
|
import {
|
|
LOAD_RECORDS
|
|
} from './constants';
|
|
|
|
export function* getRecords() {
|
|
const fakeData = [{
|
|
id: 1,
|
|
title: 'Roger Federer has won the first set.',
|
|
message: 'Try to do better than that man and you will be a winner.'
|
|
}, {
|
|
id: 2,
|
|
title: 'Lewis Hamilton is on fire.',
|
|
message: 'Did you ever seen someone like that guy?'
|
|
}, {
|
|
id: 3,
|
|
title: 'Elon Musk is awesome!',
|
|
message: 'Space X, Paypal, Tesla, & cie.'
|
|
}];
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
// Individual exports for testing
|
|
export function* defaultSaga() {
|
|
yield takeLatest(LOAD_RECORDS, getRecords);
|
|
}
|
|
|
|
// All sagas to be loaded
|
|
export default [
|
|
defaultSaga,
|
|
];
|