Skip to content

Commit 0527569

Browse files
committed
dynamicConfig: use 'function' syntax for big fns
To be more consistent with the rest of the codebase, as a rule of thumb we're having top-level functions use 'function' synax while one-liners or nested functions are arrow functions. Also, resetStoredConfig was renamed to _test_resetStoredConfig because that change is coming anyway in e-mission#1113 and this will make it easier to resolve merge conflicts
1 parent 8c31b65 commit 0527569

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

www/__tests__/enketoHelper.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '../js/survey/enketo/enketoHelper';
99
import { mockBEMUserCache } from '../__mocks__/cordovaMocks';
1010
import { mockLogger } from '../__mocks__/globalMocks';
11-
import { getConfig, resetStoredConfig } from '../../www/js/config/dynamicConfig';
11+
import { getConfig, _test_resetStoredConfig } from '../../www/js/config/dynamicConfig';
1212
import fakeConfig from '../__mocks__/fakeConfig.json';
1313

1414
import initializedI18next from '../js/i18nextInit';
@@ -21,7 +21,7 @@ global.URL = require('url').URL;
2121
global.Blob = require('node:buffer').Blob;
2222

2323
beforeEach(() => {
24-
resetStoredConfig();
24+
_test_resetStoredConfig();
2525
});
2626

2727
it('gets the survey config', async () => {

www/js/config/dynamicConfig.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ export let storedConfig = null;
1111
export let configChanged = false;
1212
export const setConfigChanged = (b) => (configChanged = b);
1313

14-
//used test multiple configs, not used outside of test
15-
export const resetStoredConfig = function () {
14+
// used to test multiple configs, not used outside of test
15+
export const _test_resetStoredConfig = () => {
1616
storedConfig = null;
1717
};
1818

19-
const _getStudyName = function (connectUrl) {
19+
function _getStudyName(connectUrl) {
2020
const orig_host = new URL(connectUrl).hostname;
2121
const first_domain = orig_host.split('.')[0];
2222
if (first_domain == 'openpath-stage') {
@@ -28,18 +28,18 @@ const _getStudyName = function (connectUrl) {
2828
}
2929
const study_name = first_domain.substr(0, openpath_index);
3030
return study_name;
31-
};
31+
}
3232

33-
const _fillStudyName = (config: Partial<AppConfig>): AppConfig => {
33+
function _fillStudyName(config: Partial<AppConfig>): AppConfig {
3434
if (config.name) return config as AppConfig;
3535
if (config.server) {
3636
return { ...config, name: _getStudyName(config.server.connectUrl) } as AppConfig;
3737
} else {
3838
return { ...config, name: 'dev' } as AppConfig;
3939
}
40-
};
40+
}
4141

42-
const _backwardsCompatSurveyFill = (config: Partial<AppConfig>): AppConfig => {
42+
function _backwardsCompatSurveyFill(config: Partial<AppConfig>): AppConfig {
4343
if (config.survey_info) return config as AppConfig;
4444
return {
4545
...config,
@@ -59,13 +59,13 @@ const _backwardsCompatSurveyFill = (config: Partial<AppConfig>): AppConfig => {
5959
'trip-labels': 'MULTILABEL',
6060
},
6161
} as AppConfig;
62-
};
62+
}
6363

6464
/* Fetch and cache any surveys resources that are referenced by URL in the config,
6565
as well as the label_options config if it is present.
6666
This way they will be available when the user needs them, and we won't have to
6767
fetch them again unless local storage is cleared. */
68-
const cacheResourcesFromConfig = (config) => {
68+
function cacheResourcesFromConfig(config) {
6969
if (config.survey_info?.surveys) {
7070
Object.values(config.survey_info.surveys).forEach((survey) => {
7171
if (!survey?.['formPath']) throw new Error(i18next.t('config.survey-missing-formpath'));
@@ -75,9 +75,9 @@ const cacheResourcesFromConfig = (config) => {
7575
if (config.label_options) {
7676
fetchUrlCached(config.label_options);
7777
}
78-
};
78+
}
7979

80-
const readConfigFromServer = async (label) => {
80+
async function readConfigFromServer(label) {
8181
const fetchedConfig = await fetchConfig(label);
8282
logDebug(`Successfully found config,
8383
fetchedConfig = ${JSON.stringify(fetchedConfig).substring(0, 10)}`);
@@ -94,9 +94,9 @@ const readConfigFromServer = async (label) => {
9494
deployment_name = ${filledConfig.intro.translated_text.en.deployment_name};
9595
connectionURL = ${fetchedConfig.server ? fetchedConfig.server.connectUrl : 'dev defaults'}`);
9696
return filledConfig;
97-
};
97+
}
9898

99-
const fetchConfig = async (label, alreadyTriedLocal = false) => {
99+
async function fetchConfig(label, alreadyTriedLocal = false) {
100100
logDebug('Received request to join ' + label);
101101
const downloadURL = `https://raw.githubusercontent.com/e-mission/nrel-openpath-deploy-configs/main/configs/${label}.nrel-op.json`;
102102
if (!__DEV__ || alreadyTriedLocal) {
@@ -115,7 +115,7 @@ const fetchConfig = async (label, alreadyTriedLocal = false) => {
115115
return fetchConfig(label, true);
116116
}
117117
}
118-
};
118+
}
119119

120120
/*
121121
* We want to support both old style and new style tokens.

0 commit comments

Comments
 (0)