43 lines
861 B
JavaScript
Raw Normal View History

2017-01-26 18:53:52 +01:00
import { takeLatest } from 'redux-saga';
import { put, select } from 'redux-saga/effects';
2017-01-26 18:53:52 +01:00
import {
loadedRecord,
} from './actions';
import {
LOAD_RECORD,
} from './constants';
import {
makeSelectCurrentModel,
} from './selectors';
export function* getRecord(params) {
const currentModel = yield select(makeSelectCurrentModel());
try {
const opts = {
method: 'GET',
mode: 'cors',
cache: 'default'
};
const response = yield fetch(`http://localhost:1337/content-manager/explorer/${currentModel}/${params.id}`, opts);
const data = yield response.json();
2017-01-26 18:53:52 +01:00
yield put(loadedRecord(data));
} catch (err) {
console.error(err);
}
2017-01-26 18:53:52 +01:00
}
// Individual exports for testing
export function* defaultSaga() {
2017-01-26 18:53:52 +01:00
yield takeLatest(LOAD_RECORD, getRecord);
}
// All sagas to be loaded
export default [
defaultSaga,
];