Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function* saveUnsavedFilesToServer(action) {
- //Don't even bother to try saving if we don't have an Internet connection
- let isConnected = yield call(NetInfo.isConnected.fetch);
- if (!isConnected) return;
- //..send files to server
- }
- function* watchToSaveFilesToServer() {
- yield throttle(
- 1000,
- [FILE_PROCESS_SUCCESS, NETWORK_INTERNET_ON],
- saveUnsavedFilesToServer
- );
- }
- export function* throttleIfConnected(ms, pattern, task, ...args) {
- const throttleChannel = yield actionChannel(pattern, buffers.sliding(1));
- while (true) {
- const action = yield take(throttleChannel);
- const isConnected = yield call(NetInfo.isConnected.fetch);
- if (isConnected) yield fork(task, ...args, action);
- yield call(delay, ms);
- }
- }
- function* throttle(ms, pattern, task, ...args) {
- const throttleChannel = yield actionChannel(pattern, buffers.sliding(1))
- while (true) {
- const action = yield take(throttleChannel)
- yield fork(task, ...args, action)
- yield call(delay, ms)
- }
- }
- export function* callIfConnected(task, ...args) {
- let isConnected = yield call(NetInfo.isConnected.fetch);
- if (isConnected) yield call(task, ...args);
- }
- const x = yield call(NetInfo.getConnectionInfo);
- if(x.type !== "none"){
- yield all([call(bestSellers), call(products)]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement