Skip to content

Commit 22aa33b

Browse files
committed
Import Input/Output without passing through gc and drop gc.mode
gc.mode needs to be dropped to avoid recursion, but in any case, it seems more sensible to just calculate it based on the currently set modeName, rather than passing it around.
1 parent 8487258 commit 22aa33b

File tree

17 files changed

+277
-253
lines changed

17 files changed

+277
-253
lines changed

root/static/scripts/edit/components/GuessCaseOptions.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import bracketed from '../../common/utility/bracketed';
1414
import getBooleanCookie from '../../common/utility/getBooleanCookie';
1515
import setCookie from '../../common/utility/setCookie';
1616
import * as modes from '../../guess-case/modes';
17+
import type {GuessCaseModeNameT} from '../../guess-case/types';
1718
import gc from '../../guess-case/MB/GuessCase/Main';
1819

1920
/* eslint-disable flowtype/sort-keys */
2021
export type ActionT =
21-
| {+type: 'set-mode', +mode: string}
22+
| {+type: 'set-mode', +modeName: GuessCaseModeNameT}
2223
| {+type: 'set-keep-upper-case', +enabled: boolean}
2324
| {+type: 'set-upper-case-roman', +enabled: boolean};
2425
/* eslint-enable flowtype/sort-keys */
@@ -27,7 +28,7 @@ export type DispatchT = (ActionT) => void;
2728

2829
export type StateT = {
2930
+keepUpperCase: boolean,
30-
+mode: string,
31+
+modeName: GuessCaseModeNameT,
3132
+upperCaseRoman: boolean,
3233
};
3334

@@ -43,7 +44,7 @@ export type PropsT = $ReadOnly<{
4344
export function createInitialState(): StateT {
4445
return {
4546
keepUpperCase: gc.CFG_KEEP_UPPERCASED,
46-
mode: gc.modeName,
47+
modeName: gc.modeName,
4748
upperCaseRoman: getBooleanCookie('guesscase_roman'),
4849
};
4950
}
@@ -54,12 +55,10 @@ export function runReducer(
5455
): void {
5556
switch (action.type) {
5657
case 'set-mode': {
57-
const modeName = action.mode;
58+
const modeName = action.modeName;
5859
gc.modeName = modeName;
59-
const mode = modes[modeName];
60-
gc.mode = mode;
6160
setCookie('guesscase_mode', modeName);
62-
state.mode = modeName;
61+
state.modeName = modeName;
6362
break;
6463
}
6564
case 'set-keep-upper-case': {
@@ -81,14 +80,14 @@ export function runReducer(
8180
const GuessCaseOptions = ({
8281
dispatch,
8382
keepUpperCase,
84-
mode: modeName,
83+
modeName,
8584
upperCaseRoman,
8685
}: PropsT): React.Element<'div'> => {
8786
function handleModeChange(event) {
8887
const newModeName = event.target.value;
8988

9089
if (newModeName !== gc.modeName) {
91-
dispatch({mode: newModeName, type: 'set-mode'});
90+
dispatch({modeName: newModeName, type: 'set-mode'});
9291
}
9392
}
9493

@@ -122,7 +121,7 @@ const GuessCaseOptions = ({
122121
</a>,
123122
)}
124123
<p>
125-
{expand2react(gc.mode?.description ?? '')}
124+
{expand2react(modes[modeName].description ?? '')}
126125
</p>
127126
<label>
128127
<input

root/static/scripts/edit/components/GuessCaseOptionsPopover.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const GuessCaseOptionsPopover = (React.memo(({
3030
dispatch,
3131
isOpen,
3232
keepUpperCase,
33-
mode,
33+
modeName,
3434
toggle,
3535
upperCaseRoman,
3636
}: Props): React.Element<typeof ButtonPopover> => {
@@ -48,7 +48,7 @@ const GuessCaseOptionsPopover = (React.memo(({
4848
<GuessCaseOptions
4949
dispatch={dispatch}
5050
keepUpperCase={keepUpperCase}
51-
mode={mode}
51+
modeName={modeName}
5252
upperCaseRoman={upperCaseRoman}
5353
/>
5454
<div
@@ -72,7 +72,7 @@ const GuessCaseOptionsPopover = (React.memo(({
7272
), [
7373
dispatch,
7474
keepUpperCase,
75-
mode,
75+
modeName,
7676
upperCaseRoman,
7777
]);
7878

root/static/scripts/guess-case/MB/Control/GuessCase.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ var mode = ko.computed({
7575

7676
if (modeName !== gc.modeName) {
7777
gc.modeName = modeName;
78-
gc.mode = modes[modeName];
7978
setCookie('guesscase_mode', modeName);
8079
}
81-
return gc.mode;
80+
return modes[modeName];
8281
},
8382
deferEvaluation: true,
8483
});

root/static/scripts/guess-case/MB/GuessCase/Handler/Area.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import MB from '../../../../common/MB';
1010
import * as flags from '../../../flags';
11+
import * as modes from '../../../modes';
1112
import * as utils from '../../../utils';
1213

1314
MB.GuessCase = (MB.GuessCase) ? MB.GuessCase : {};
@@ -33,7 +34,7 @@ MB.GuessCase.Handler.Area = function (gc) {
3334
(
3435
self.doIgnoreWords() ||
3536
self.doFeaturingArtistStyle() ||
36-
gc.mode.doWord() ||
37+
modes[gc.modeName].doWord() ||
3738
self.doNormalWord()
3839
);
3940
flags.context.number = false;

root/static/scripts/guess-case/MB/GuessCase/Handler/Artist.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import MB from '../../../../common/MB';
1111
import * as flags from '../../../flags';
1212
import * as utils from '../../../utils';
13+
import input from '../Input';
14+
import output from '../Output';
1315

1416
MB.GuessCase = (MB.GuessCase) ? MB.GuessCase : {};
1517
MB.GuessCase.Handler = (MB.GuessCase.Handler) ? MB.GuessCase.Handler : {};
@@ -61,9 +63,9 @@ MB.GuessCase.Handler.Artist = function (gc) {
6163
* in the common word handlers.
6264
*/
6365
self.doWord = function () {
64-
gc.output.appendSpaceIfNeeded();
65-
gc.input.capitalizeCurrentWord();
66-
gc.output.appendCurrentWord();
66+
output.appendSpaceIfNeeded();
67+
input.capitalizeCurrentWord();
68+
output.appendCurrentWord();
6769

6870
flags.resetContext();
6971
flags.context.number = false;

0 commit comments

Comments
 (0)