mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Memoized the loading of the server version, assuming it will not change at runtime
This commit is contained in:
parent
25c67f1c3e
commit
5145a41dac
2 changed files with 454 additions and 449 deletions
890
package-lock.json
generated
890
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
||||||
import { createAction, handleActions } from 'redux-actions';
|
import { createAction, handleActions } from 'redux-actions';
|
||||||
import { pipe } from 'ramda';
|
import { identity, memoizeWith, pipe } from 'ramda';
|
||||||
import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams';
|
import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams';
|
||||||
import { versionToPrintable, versionToSemVer as toSemVer } from '../../utils/versionHelpers';
|
import { versionToPrintable, versionToSemVer as toSemVer } from '../../utils/versionHelpers';
|
||||||
|
|
||||||
|
@ -36,14 +36,14 @@ export const selectServer = ({ findServerById }, buildShlinkApiClient) => (serve
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { health } = buildShlinkApiClient(selectedServer);
|
const { health } = buildShlinkApiClient(selectedServer);
|
||||||
const { version } = await health();
|
const { version, printableVersion } = await getServerVersion(serverId, health);
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SELECT_SERVER,
|
type: SELECT_SERVER,
|
||||||
selectedServer: {
|
selectedServer: {
|
||||||
...selectedServer,
|
...selectedServer,
|
||||||
version: versionToSemVer(version),
|
version,
|
||||||
printableVersion: versionToPrintable(version),
|
printableVersion,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -54,6 +54,11 @@ export const selectServer = ({ findServerById }, buildShlinkApiClient) => (serve
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getServerVersion = memoizeWith(identity, (serverId, health) => health().then(({ version }) => ({
|
||||||
|
version: versionToSemVer(version),
|
||||||
|
printableVersion: versionToPrintable(version),
|
||||||
|
})));
|
||||||
|
|
||||||
export default handleActions({
|
export default handleActions({
|
||||||
[RESET_SELECTED_SERVER]: () => initialState,
|
[RESET_SELECTED_SERVER]: () => initialState,
|
||||||
[SELECT_SERVER]: (state, { selectedServer }) => selectedServer,
|
[SELECT_SERVER]: (state, { selectedServer }) => selectedServer,
|
||||||
|
|
Loading…
Reference in a new issue