Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// NOTE: need to avoid hoisting generator functions or they'll happen
// before this definition. See garbageCollector definition below, e.g.
// TODO: The `Effect` type is not actually defined. Because 'redux-saga' does
// not use annotations, flow pretends that this import succeeds.
var regeneratorRuntime = require('regenerator-runtime');
var delay = function delay(ms) {
return new Promise(function (resolve) {
return setTimeout(resolve, ms);
});
};
var garbageCollector = regeneratorRuntime.mark(function garbageCollector() {
return regeneratorRuntime.wrap(function garbageCollector$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return (0, _effects.call)(delay, _cachePeriod.cachePeriod);
case 2:
_context.next = 4;
return (0, _effects.call)(delay, _cachePeriod.halfCachePeriod);
case 4:
_context.next = 6;
return (0, _effects.put)({ type: _actionTypes.GARBAGE_COLLECT, meta: { now: Date.now() } });
case 6:
var watchCreate = function watchCreate(apiClient) {
return regeneratorRuntime.mark(function _watchCreate() {
return regeneratorRuntime.wrap(function _watchCreate$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return (0, _effects.takeEvery)(_actionTypes.CREATE, apiGeneric(apiClient));
case 2:
case 'end':
return _context5.stop();
}
}
}, _watchCreate, this);
});
};
var watchApiCall = function watchApiCall(apiClient) {
return regeneratorRuntime.mark(function _watchApiCall() {
return regeneratorRuntime.wrap(function _watchApiCall$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.next = 2;
return (0, _effects.takeEvery)(_actionTypes.API_CALL, apiGeneric(apiClient));
case 2:
case 'end':
return _context8.stop();
}
}
}, _watchApiCall, this);
});
};
var watchFetchOne = function watchFetchOne(apiClient) {
return regeneratorRuntime.mark(function _watchFetchOne() {
return regeneratorRuntime.wrap(function _watchFetchOne$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return (0, _effects.takeEvery)(_actionTypes.FETCH_ONE, apiGeneric(apiClient));
case 2:
case 'end':
return _context4.stop();
}
}
}, _watchFetchOne, this);
});
};
var watchUpdate = function watchUpdate(apiClient) {
return regeneratorRuntime.mark(function _watchUpdate() {
return regeneratorRuntime.wrap(function _watchUpdate$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.next = 2;
return (0, _effects.takeEvery)(_actionTypes.UPDATE, apiGeneric(apiClient));
case 2:
case 'end':
return _context6.stop();
}
}
}, _watchUpdate, this);
});
};
var watchDelete = function watchDelete(apiClient) {
return regeneratorRuntime.mark(function _watchDelete() {
return regeneratorRuntime.wrap(function _watchDelete$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return (0, _effects.takeEvery)(_actionTypes.DELETE, apiGeneric(apiClient));
case 2:
case 'end':
return _context7.stop();
}
}
}, _watchDelete, this);
});
};
function crudSaga(apiClient) {
return regeneratorRuntime.mark(function _crudSaga() {
return regeneratorRuntime.wrap(function _crudSaga$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
_context9.next = 2;
return (0, _effects.all)([(0, _effects.fork)(watchFetch(apiClient)), (0, _effects.fork)(watchFetchOne(apiClient)), (0, _effects.fork)(watchCreate(apiClient)), (0, _effects.fork)(watchUpdate(apiClient)), (0, _effects.fork)(watchDelete(apiClient)), (0, _effects.fork)(watchApiCall(apiClient)), (0, _effects.fork)(garbageCollector)]);
case 2:
case 'end':
return _context9.stop();
}
}
}, _crudSaga, this);
});
}
var watchFetch = function watchFetch(apiClient) {
return regeneratorRuntime.mark(function _watchFetch() {
return regeneratorRuntime.wrap(function _watchFetch$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return (0, _effects.takeEvery)(_actionTypes.FETCH, apiGeneric(apiClient));
case 2:
case 'end':
return _context3.stop();
}
}
}, _watchFetch, this);
});
};