Skip to content

Commit 8eda485

Browse files
committed
Don't store the IntlShape in ProgramChangeController
1 parent 7025d49 commit 8eda485

3 files changed

Lines changed: 142 additions & 122 deletions

File tree

src/App.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export class App extends React.Component<AppProps, AppState> {
264264
this.designModeCursorDescriptionBuilder = new DesignModeCursorDescriptionBuilder();
265265

266266
this.programChangeController = new ProgramChangeController(this,
267-
this.props.intl, this.audioManager);
267+
this.audioManager);
268268

269269
this.programBlockEditorRef = React.createRef();
270270

@@ -362,23 +362,26 @@ export class App extends React.Component<AppProps, AppState> {
362362
this.programChangeController.insertSelectedActionIntoProgram(
363363
this.programBlockEditorRef.current,
364364
index,
365-
selectedAction
365+
selectedAction,
366+
this.props.intl
366367
);
367368
};
368369

369370
handleProgramBlockEditorDeleteStep = (index: number, command: string) => {
370371
this.programChangeController.deleteProgramStep(
371372
this.programBlockEditorRef.current,
372373
index,
373-
command
374+
command,
375+
this.props.intl
374376
);
375377
};
376378

377379
handleProgramBlockEditorReplaceStep = (index: number, selectedAction: ?CommandName) => {
378380
this.programChangeController.replaceProgramStep(
379381
this.programBlockEditorRef.current,
380382
index,
381-
selectedAction
383+
selectedAction,
384+
this.props.intl
382385
);
383386
};
384387

@@ -387,7 +390,8 @@ export class App extends React.Component<AppProps, AppState> {
387390
this.programBlockEditorRef.current,
388391
indexFrom,
389392
commandAtIndexFrom,
390-
'focusActionPanel'
393+
'focusActionPanel',
394+
this.props.intl
391395
)
392396
};
393397

@@ -396,7 +400,8 @@ export class App extends React.Component<AppProps, AppState> {
396400
this.programBlockEditorRef.current,
397401
indexFrom,
398402
commandAtIndexFrom,
399-
'focusActionPanel'
403+
'focusActionPanel',
404+
this.props.intl
400405
)
401406
};
402407

@@ -576,7 +581,8 @@ export class App extends React.Component<AppProps, AppState> {
576581
this.programChangeController.insertSelectedActionIntoProgram(
577582
this.programBlockEditorRef.current,
578583
index,
579-
this.state.selectedAction
584+
this.state.selectedAction,
585+
this.props.intl
580586
);
581587
}
582588
}
@@ -589,15 +595,17 @@ export class App extends React.Component<AppProps, AppState> {
589595
this.programChangeController.insertSelectedActionIntoProgram(
590596
this.programBlockEditorRef.current,
591597
0,
592-
this.state.selectedAction
598+
this.state.selectedAction,
599+
this.props.intl
593600
);
594601
}
595602
break;
596603
case("addCommandToEnd"):
597604
if (!this.isEditingDisabled()) {
598605
this.programChangeController.addSelectedActionToProgramEnd(
599606
this.programBlockEditorRef.current,
600-
this.state.selectedAction
607+
this.state.selectedAction,
608+
this.props.intl
601609
);
602610
}
603611
break;
@@ -611,7 +619,8 @@ export class App extends React.Component<AppProps, AppState> {
611619
this.programChangeController.deleteProgramStep(
612620
this.programBlockEditorRef.current,
613621
index,
614-
currentElement.dataset.command
622+
currentElement.dataset.command,
623+
this.props.intl
615624
);
616625
}
617626
}
@@ -628,7 +637,8 @@ export class App extends React.Component<AppProps, AppState> {
628637
this.programChangeController.replaceProgramStep(
629638
this.programBlockEditorRef.current,
630639
index,
631-
this.state.selectedAction
640+
this.state.selectedAction,
641+
this.props.intl
632642
);
633643
}
634644
}
@@ -770,7 +780,8 @@ export class App extends React.Component<AppProps, AppState> {
770780
this.programBlockEditorRef.current,
771781
index,
772782
currentElement.dataset.command,
773-
'focusBlockMoved'
783+
'focusBlockMoved',
784+
this.props.intl
774785
)
775786
}
776787
}
@@ -788,7 +799,8 @@ export class App extends React.Component<AppProps, AppState> {
788799
this.programBlockEditorRef.current,
789800
index,
790801
currentElement.dataset.command,
791-
'focusBlockMoved'
802+
'focusBlockMoved',
803+
this.props.intl
792804
)
793805
}
794806
}

src/ProgramChangeController.js

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,21 @@ type FocusAfterMoveEnum = 'focusBlockMoved' | 'focusActionPanel';
1818

1919
export default class ProgramChangeController {
2020
app: App;
21-
intl: IntlShape;
2221
audioManager: AudioManager;
2322
announcementBuilder: AnnouncementBuilder;
2423

25-
constructor(app: App, intl: IntlShape, audioManager: AudioManager) {
24+
constructor(app: App, audioManager: AudioManager) {
2625
this.app = app;
27-
this.intl = intl;
2826
this.audioManager = audioManager;
2927
this.announcementBuilder = new AnnouncementBuilder();
3028
}
3129

3230
insertSelectedActionIntoProgram(programBlockEditor: ?ProgramBlockEditor,
33-
index: number, selectedAction: ?CommandName) {
31+
index: number, selectedAction: ?CommandName, intl: IntlShape) {
3432

3533
this.app.setState((state) => {
3634
if (selectedAction) {
37-
this.playAnnouncementForAdd(selectedAction);
35+
this.playAnnouncementForAdd(selectedAction, intl);
3836
this.doActivitiesForAdd(programBlockEditor, index);
3937
return {
4038
programSequence: state.programSequence.insertStep(index,
@@ -47,11 +45,11 @@ export default class ProgramChangeController {
4745
}
4846

4947
addSelectedActionToProgramEnd(programBlockEditor: ?ProgramBlockEditor,
50-
selectedAction: ?CommandName) {
48+
selectedAction: ?CommandName, intl: IntlShape) {
5149

5250
this.app.setState((state) => {
5351
if (selectedAction) {
54-
this.playAnnouncementForAdd(selectedAction);
52+
this.playAnnouncementForAdd(selectedAction, intl);
5553
const index = state.programSequence.getProgramLength();
5654
this.doActivitiesForAdd(programBlockEditor, index);
5755
return {
@@ -65,17 +63,17 @@ export default class ProgramChangeController {
6563
}
6664

6765
deleteProgramStep(programBlockEditor: ?ProgramBlockEditor,
68-
index: number, command: string) {
66+
index: number, command: string, intl: IntlShape) {
6967

7068
this.app.setState((state) => {
7169
// Check that the step to delete hasn't changed since the
7270
// user made the deletion
7371
const currentStep = state.programSequence.getProgramStepAt(index);
7472
if (command === currentStep.block) {
7573
// Play the announcement
76-
const announcementData = this.announcementBuilder.buildDeleteStepAnnouncement(currentStep, this.intl);
74+
const announcementData = this.announcementBuilder.buildDeleteStepAnnouncement(currentStep, intl);
7775
this.audioManager.playAnnouncement(announcementData.messageIdSuffix,
78-
this.intl, announcementData.values);
76+
intl, announcementData.values);
7977

8078
if (programBlockEditor) {
8179
// If there are steps following the one being deleted, focus
@@ -115,19 +113,19 @@ export default class ProgramChangeController {
115113
}
116114

117115
replaceProgramStep(programBlockEditor: ?ProgramBlockEditor,
118-
index: number, selectedAction: ?CommandName) {
116+
index: number, selectedAction: ?CommandName, intl: IntlShape) {
119117

120118
this.app.setState((state) => {
121119
const currentStep = state.programSequence.getProgramStepAt(index);
122120
if (isLoopBlock(currentStep.block)) {
123-
this.audioManager.playAnnouncement('cannotReplaceLoopBlocks', this.intl);
121+
this.audioManager.playAnnouncement('cannotReplaceLoopBlocks', intl);
124122
return {};
125123
} else if (selectedAction) {
126124
// Play the announcement
127125
const announcementData = this.announcementBuilder.buildReplaceStepAnnouncement(
128-
currentStep, selectedAction, this.intl);
126+
currentStep, selectedAction, intl);
129127
this.audioManager.playAnnouncement(announcementData.messageIdSuffix,
130-
this.intl, announcementData.values);
128+
intl, announcementData.values);
131129

132130
// Set up focus, scrolling, and animation
133131
if (programBlockEditor) {
@@ -140,15 +138,15 @@ export default class ProgramChangeController {
140138
programSequence: state.programSequence.overwriteStep(index, selectedAction)
141139
};
142140
} else {
143-
this.audioManager.playAnnouncement('noActionSelected', this.intl);
141+
this.audioManager.playAnnouncement('noActionSelected', intl);
144142
return {};
145143
}
146144
});
147145
}
148146

149147
moveProgramStepNext(programBlockEditor: ?ProgramBlockEditor,
150148
indexFrom: number, commandAtIndexFrom: string,
151-
focusAfterMove: FocusAfterMoveEnum) {
149+
focusAfterMove: FocusAfterMoveEnum, intl: IntlShape) {
152150

153151
this.app.setState((state) => {
154152
// Check that the step at indexFrom has not changed
@@ -157,11 +155,11 @@ export default class ProgramChangeController {
157155
if (state.programSequence.moveToNextStepDisabled(indexFrom)) {
158156
// Move next is not possible:
159157
// Play an announcement and do not change the program
160-
this.audioManager.playAnnouncement('cannotMoveNext', this.intl);
158+
this.audioManager.playAnnouncement('cannotMoveNext', intl);
161159
return {};
162160
} else {
163161
// Play the announcement
164-
this.audioManager.playAnnouncement('moveToNext', this.intl);
162+
this.audioManager.playAnnouncement('moveToNext', intl);
165163

166164
return this.doMove(
167165
programBlockEditor,
@@ -181,7 +179,7 @@ export default class ProgramChangeController {
181179

182180
moveProgramStepPrevious(programBlockEditor: ?ProgramBlockEditor,
183181
indexFrom: number, commandAtIndexFrom: string,
184-
focusAfterMove: FocusAfterMoveEnum) {
182+
focusAfterMove: FocusAfterMoveEnum, intl: IntlShape) {
185183

186184
this.app.setState((state) => {
187185
// Check that the step at indexFrom has not changed
@@ -190,11 +188,11 @@ export default class ProgramChangeController {
190188
if (state.programSequence.moveToPreviousStepDisabled(indexFrom)) {
191189
// Move previous is not possible:
192190
// Play an announcement and do not change the program
193-
this.audioManager.playAnnouncement('cannotMovePrevious', this.intl);
191+
this.audioManager.playAnnouncement('cannotMovePrevious', intl);
194192
return {};
195193
} else {
196194
// Play the announcement
197-
this.audioManager.playAnnouncement('moveToPrevious', this.intl);
195+
this.audioManager.playAnnouncement('moveToPrevious', intl);
198196

199197
return this.doMove(
200198
programBlockEditor,
@@ -214,10 +212,10 @@ export default class ProgramChangeController {
214212

215213
// Internal methods
216214

217-
playAnnouncementForAdd(action: string) {
218-
const announcementData = this.announcementBuilder.buildAddStepAnnouncement(action, this.intl);
215+
playAnnouncementForAdd(action: string, intl: IntlShape) {
216+
const announcementData = this.announcementBuilder.buildAddStepAnnouncement(action, intl);
219217
this.audioManager.playAnnouncement(announcementData.messageIdSuffix,
220-
this.intl, announcementData.values);
218+
intl, announcementData.values);
221219
}
222220

223221
doActivitiesForAdd(programBlockEditor: ?ProgramBlockEditor, index: number) {

0 commit comments

Comments
 (0)