Skip to content

Commit

Permalink
Reorganize saga functions orders to be in the same order they are cal…
Browse files Browse the repository at this point in the history
…led in
  • Loading branch information
steinarb committed Mar 26, 2024
1 parent c884966 commit a150294
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
ACCOUNTS_FAILURE,
} from '../reduxactions';

function sendAccounts() {
return axios.get('/api/accounts');
export default function* accountsSaga() {
yield takeLatest(ACCOUNTS_REQUEST, mottaAccountsResult);
}

function* mottaAccountsResult() {
Expand All @@ -20,6 +20,6 @@ function* mottaAccountsResult() {
}
}

export default function* accountsSaga() {
yield takeLatest(ACCOUNTS_REQUEST, mottaAccountsResult);
function sendAccounts() {
return axios.get('/api/accounts');
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export default function* availableLocalesSaga() {
yield takeLatest(AVAILABLE_LOCALES_REQUEST, receiveAvailableLocalesSaga);
}

function doAvailableLocales() {
return axios.get('/api/availablelocales');
}

// worker saga
function* receiveAvailableLocalesSaga() {
try {
Expand All @@ -25,3 +21,7 @@ function* receiveAvailableLocalesSaga() {
yield put(AVAILABLE_LOCALES_FAILURE(error));
}
}

function doAvailableLocales() {
return axios.get('/api/availablelocales');
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import {
INCREMENT_STEP_FIELD_MODIFIED,
} from '../reduxactions';

function getCounterIncrementStep(username) {
return axios.get('/api/counter/incrementstep/' + username);
export default function* counterIncrementStepSaga() {
yield takeLatest(COUNTER_INCREMENT_STEP_REQUEST, fetchCounterIncrementStep);
yield takeLatest(LOGIN_RECEIVE, fetchCounterIncrementStep);
yield takeLatest(LOGINSTATE_RECEIVE, fetchCounterIncrementStep);
yield takeLatest(UPDATE_COUNTER_INCREMENT_STEP_REQUEST, updateCounterIncrementStep);
yield takeLatest(INCREMENT_STEP_FIELD_MODIFIED, updateCounterIncrementStepAfterDelay);
}

function* fetchCounterIncrementStep() {
Expand All @@ -30,8 +34,8 @@ function* fetchCounterIncrementStep() {
}
}

function postCounterIncrementStep(updatedCounterIncrementStep) {
return axios.post('/api/counter/incrementstep/', updatedCounterIncrementStep);
function getCounterIncrementStep(username) {
return axios.get('/api/counter/incrementstep/' + username);
}

function* updateCounterIncrementStep(action) {
Expand All @@ -49,15 +53,11 @@ function* updateCounterIncrementStep(action) {
}
}

function postCounterIncrementStep(updatedCounterIncrementStep) {
return axios.post('/api/counter/incrementstep/', updatedCounterIncrementStep);
}

function* updateCounterIncrementStepAfterDelay(action) {
yield delay(2000);
yield put(UPDATE_COUNTER_INCREMENT_STEP_REQUEST(action.payload));
}

export default function* counterIncrementStepSaga() {
yield takeLatest(COUNTER_INCREMENT_STEP_REQUEST, fetchCounterIncrementStep);
yield takeLatest(LOGIN_RECEIVE, fetchCounterIncrementStep);
yield takeLatest(LOGINSTATE_RECEIVE, fetchCounterIncrementStep);
yield takeLatest(UPDATE_COUNTER_INCREMENT_STEP_REQUEST, updateCounterIncrementStep);
yield takeLatest(INCREMENT_STEP_FIELD_MODIFIED, updateCounterIncrementStepAfterDelay);
}
20 changes: 10 additions & 10 deletions sampleapp.web.frontend/src/main/frontend/src/sagas/counterSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ import {
LOGINSTATE_RECEIVE,
} from '../reduxactions';

function getCounter(username) {
return axios.get('/api/counter/' + username);
export default function* counterSaga() {
yield takeLatest(COUNTER_REQUEST, fetchCounter);
yield takeLatest(LOGIN_RECEIVE, fetchCounter);
yield takeLatest(LOGINSTATE_RECEIVE, fetchCounter);
yield takeLatest(COUNTER_DECREMENT_REQUEST, decrementCounter);
yield takeLatest(COUNTER_INCREMENT_REQUEST, incrementCounter);
}

function* fetchCounter() {
Expand All @@ -32,8 +36,8 @@ function* fetchCounter() {
}
}

function getDecrementCounter(username) {
return axios.get('/api/counter/' + username + '/decrement');
function getCounter(username) {
return axios.get('/api/counter/' + username);
}

function* decrementCounter() {
Expand Down Expand Up @@ -69,10 +73,6 @@ function* incrementCounter() {
}
}

export default function* counterSaga() {
yield takeLatest(COUNTER_REQUEST, fetchCounter);
yield takeLatest(LOGIN_RECEIVE, fetchCounter);
yield takeLatest(LOGINSTATE_RECEIVE, fetchCounter);
yield takeLatest(COUNTER_DECREMENT_REQUEST, decrementCounter);
yield takeLatest(COUNTER_INCREMENT_REQUEST, incrementCounter);
function getDecrementCounter(username) {
return axios.get('/api/counter/' + username + '/decrement');
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export default function* defaultLocaleSaga() {
yield takeLatest(DEFAULT_LOCALE_REQUEST, receiveDefaultLocaleSaga);
}

function doDefaultLocale() {
return axios.get('/api/defaultlocale');
}

// worker saga
function* receiveDefaultLocaleSaga() {
try {
Expand All @@ -25,3 +21,7 @@ function* receiveDefaultLocaleSaga() {
yield put(DEFAULT_LOCALE_FAILURE(error));
}
}

function doDefaultLocale() {
return axios.get('/api/defaultlocale');
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export default function* displayTextsSaga() {
yield takeLatest(SELECT_LOCALE, receiveDisplayTextsSaga);
}

function doDisplayTexts(locale) {
return axios.get('/api/displaytexts', { params: { locale } });
}

// worker saga
function* receiveDisplayTextsSaga(action) {
try {
Expand All @@ -27,3 +23,7 @@ function* receiveDisplayTextsSaga(action) {
yield put(DISPLAY_TEXTS_FAILURE(error));
}
}

function doDisplayTexts(locale) {
return axios.get('/api/displaytexts', { params: { locale } });
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { takeLatest, put, select } from 'redux-saga/effects';
import { LOCATION_CHANGE } from 'redux-first-history';
import { ACCOUNTS_REQUEST } from '../reduxactions';

export default function* locationSaga() {
yield takeLatest(LOCATION_CHANGE, locationChange);
}

function* locationChange(action) {
const { location = {} } = action.payload || {};
const basename = yield select(state => state.router.basename);
Expand All @@ -12,10 +16,6 @@ function* locationChange(action) {
}
}

export default function* locationSaga() {
yield takeLatest(LOCATION_CHANGE, locationChange);
}

function findPathname(location, basename) {
if (basename === '/') {
return location.pathname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
LOGIN_FAILURE,
} from '../reduxactions';

function sendLogin(credentials, locale) {
return axios.post('/api/login', credentials, { params: { locale } });
export default function* loginSaga() {
yield takeLatest(LOGIN_REQUEST, mottaLoginResult);
}

function* mottaLoginResult(action) {
Expand All @@ -21,6 +21,6 @@ function* mottaLoginResult(action) {
}
}

export default function* loginSaga() {
yield takeLatest(LOGIN_REQUEST, mottaLoginResult);
function sendLogin(credentials, locale) {
return axios.post('/api/login', credentials, { params: { locale } });
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
LOGINSTATE_FAILURE,
} from '../reduxactions';

function sendLoginstate(locale) {
return axios.get('/api/loginstate', { params: { locale } });
export default function* loginstateSaga() {
yield takeLatest(LOGINSTATE_REQUEST, mottaLoginstateResult);
}

function* mottaLoginstateResult() {
Expand All @@ -21,6 +21,6 @@ function* mottaLoginstateResult() {
}
}

export default function* loginstateSaga() {
yield takeLatest(LOGINSTATE_REQUEST, mottaLoginstateResult);
function sendLoginstate(locale) {
return axios.get('/api/loginstate', { params: { locale } });
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
LOGOUT_FAILURE,
} from '../reduxactions';

function sendLogout(locale) {
return axios.get('/api/logout', { params: { locale } });
export default function* logoutSaga() {
yield takeLatest(LOGOUT_REQUEST, mottaLogoutResult);
}

function* mottaLogoutResult() {
Expand All @@ -21,6 +21,6 @@ function* mottaLogoutResult() {
}
}

export default function* logoutSaga() {
yield takeLatest(LOGOUT_REQUEST, mottaLogoutResult);
function sendLogout(locale) {
return axios.get('/api/logout', { params: { locale } });
}

0 comments on commit a150294

Please sign in to comment.