Skip to content

Commit 57915b7

Browse files
committed
Don't store the IntlShape in CharacterDescriptionBuilder
1 parent 319bd39 commit 57915b7

7 files changed

Lines changed: 43 additions & 40 deletions

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class App extends React.Component<AppProps, AppState> {
259259

260260
this.announcementBuilder = new AnnouncementBuilder(this.props.intl);
261261

262-
this.characterDescriptionBuilder = new CharacterDescriptionBuilder(this.props.intl);
262+
this.characterDescriptionBuilder = new CharacterDescriptionBuilder();
263263

264264
this.designModeCursorDescriptionBuilder = new DesignModeCursorDescriptionBuilder(this.props.intl);
265265

src/CharacterAriaLive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class CharacterAriaLive extends React.Component<CharacterAriaLiveProps, {}> {
7171
text += this.props.characterDescriptionBuilder.buildDescription(
7272
this.props.characterState,
7373
this.props.world,
74-
this.props.customBackground
74+
this.props.customBackground,
75+
this.props.intl
7576
);
7677

7778
this.setLiveRegion(text);

src/CharacterAriaLive.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const defaultCharacterAriaLiveProps = {
4545
world: 'Sketchpad',
4646
customBackground: emptyCustomBackground,
4747
customBackgroundDesignMode: false,
48-
characterDescriptionBuilder: new CharacterDescriptionBuilder(intl),
48+
characterDescriptionBuilder: new CharacterDescriptionBuilder(),
4949
designModeCursorDescriptionBuilder: new DesignModeCursorDescriptionBuilder(intl),
5050
message: null
5151
};

src/CharacterDescriptionBuilder.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ import { getBackgroundSquareDescription } from './Utils';
77
import type { WorldName } from './Worlds';
88

99
export default class CharacterDescriptionBuilder {
10-
intl: IntlShape;
11-
12-
constructor(intl: IntlShape) {
13-
this.intl = intl;
14-
}
15-
1610
buildDescription(characterState: CharacterState,
17-
world: WorldName, customBackground: CustomBackground): string {
11+
world: WorldName, customBackground: CustomBackground,
12+
intl: IntlShape): string {
1813

1914
const columnLabel = characterState.getColumnLabel();
2015
const rowLabel = characterState.getRowLabel();
@@ -25,13 +20,13 @@ export default class CharacterDescriptionBuilder {
2520
characterState.sceneDimensions,
2621
world,
2722
customBackground,
28-
this.intl
23+
intl
2924
);
3025

31-
const directionLabel = this.intl.formatMessage({id: `Direction.${characterState.direction}`});
26+
const directionLabel = intl.formatMessage({id: `Direction.${characterState.direction}`});
3227

3328
if (itemLabel) {
34-
return this.intl.formatMessage(
29+
return intl.formatMessage(
3530
{
3631
id:'CharacterDescriptionBuilder.positionAndDirectionAndItem'
3732
},
@@ -43,7 +38,7 @@ export default class CharacterDescriptionBuilder {
4338
}
4439
);
4540
} else {
46-
return this.intl.formatMessage(
41+
return intl.formatMessage(
4742
{
4843
id:'CharacterDescriptionBuilder.positionAndDirection'
4944
},

src/CharacterDescriptionBuilder.test.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,94 +17,106 @@ const sceneDimensions = new SceneDimensions(1, 12, 1, 8);
1717
const emptyCustomBackground = new CustomBackground(sceneDimensions);
1818

1919
test('All 8 directions', () => {
20-
const builder = new CharacterDescriptionBuilder(intl);
20+
const builder = new CharacterDescriptionBuilder();
2121

2222
expect(builder.buildDescription(
2323
new CharacterState(1, 1, 0, [], sceneDimensions),
2424
'Sketchpad',
25-
emptyCustomBackground
25+
emptyCustomBackground,
26+
intl
2627
)).toBe('At A 1 facing up');
2728

2829
expect(builder.buildDescription(
2930
new CharacterState(1, 1, 1, [], sceneDimensions),
3031
'Sketchpad',
31-
emptyCustomBackground
32+
emptyCustomBackground,
33+
intl
3234
)).toBe('At A 1 facing upper right');
3335

3436
expect(builder.buildDescription(
3537
new CharacterState(1, 1, 2, [], sceneDimensions),
3638
'Sketchpad',
37-
emptyCustomBackground
39+
emptyCustomBackground,
40+
intl
3841
)).toBe('At A 1 facing right');
3942

4043
expect(builder.buildDescription(
4144
new CharacterState(1, 1, 3, [], sceneDimensions),
4245
'Sketchpad',
43-
emptyCustomBackground
46+
emptyCustomBackground,
47+
intl
4448
)).toBe('At A 1 facing lower right');
4549

4650
expect(builder.buildDescription(
4751
new CharacterState(1, 1, 4, [], sceneDimensions),
4852
'Sketchpad',
49-
emptyCustomBackground
53+
emptyCustomBackground,
54+
intl
5055
)).toBe('At A 1 facing down');
5156

5257
expect(builder.buildDescription(
5358
new CharacterState(1, 1, 5, [], sceneDimensions),
5459
'Sketchpad',
55-
emptyCustomBackground
60+
emptyCustomBackground,
61+
intl
5662
)).toBe('At A 1 facing lower left');
5763

5864
expect(builder.buildDescription(
5965
new CharacterState(1, 1, 6, [], sceneDimensions),
6066
'Sketchpad',
61-
emptyCustomBackground
67+
emptyCustomBackground,
68+
intl
6269
)).toBe('At A 1 facing left');
6370

6471
expect(builder.buildDescription(
6572
new CharacterState(1, 1, 7, [], sceneDimensions),
6673
'Sketchpad',
67-
emptyCustomBackground
74+
emptyCustomBackground,
75+
intl
6876
)).toBe('At A 1 facing upper left');
6977
});
7078

7179
test('Space, background description: no, custom background tile: no', () => {
72-
const builder = new CharacterDescriptionBuilder(intl);
80+
const builder = new CharacterDescriptionBuilder();
7381
expect(builder.buildDescription(
7482
new CharacterState(3, 2, 2, [], sceneDimensions),
7583
'Space',
76-
emptyCustomBackground
84+
emptyCustomBackground,
85+
intl
7786
)).toBe('At C 2 facing right');
7887
});
7988

8089
test('Space, background description: no, custom background tile: yes', () => {
81-
const builder = new CharacterDescriptionBuilder(intl);
90+
const builder = new CharacterDescriptionBuilder();
8291
expect(builder.buildDescription(
8392
new CharacterState(3, 2, 2, [], sceneDimensions),
8493
'Space',
8594
new CustomBackground(sceneDimensions, [
8695
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
8796
'0', '0', '1'
88-
])
97+
]),
98+
intl
8999
)).toBe('At C 2 on wall facing right');
90100
});
91101

92102
test('Space, background description: yes, custom background tile: no', () => {
93-
const builder = new CharacterDescriptionBuilder(intl);
103+
const builder = new CharacterDescriptionBuilder();
94104
expect(builder.buildDescription(
95105
new CharacterState(3, 1, 2, [], sceneDimensions),
96106
'Space',
97-
emptyCustomBackground
107+
emptyCustomBackground,
108+
intl
98109
)).toBe('At C 1 on the Moon facing right');
99110
});
100111

101112
test('Space, background description: yes, custom background tile: yes', () => {
102-
const builder = new CharacterDescriptionBuilder(intl);
113+
const builder = new CharacterDescriptionBuilder();
103114
expect(builder.buildDescription(
104115
new CharacterState(3, 1, 2, [], sceneDimensions),
105116
'Space',
106117
new CustomBackground(sceneDimensions, [
107118
'0', '0', '1'
108-
])
119+
]),
120+
intl
109121
)).toBe('At C 1 on wall facing right');
110122
});

src/Scene.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class Scene extends React.Component<SceneProps, {}> {
7575
const characterDescription = this.props.characterDescriptionBuilder.buildDescription(
7676
this.props.characterState,
7777
this.props.world,
78-
this.props.customBackground
78+
this.props.customBackground,
79+
this.props.intl
7980
);
8081

8182
return this.props.intl.formatMessage(

src/Scene.test.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React from 'react';
44
import Adapter from 'enzyme-adapter-react-16';
55
import { configure, mount } from 'enzyme';
6-
import { createIntl, IntlProvider } from 'react-intl';
6+
import { IntlProvider } from 'react-intl';
77
import messages from './messages.json';
88
import Scene from './Scene';
99
import type {SceneProps} from './Scene';
@@ -15,12 +15,6 @@ import DesignModeCursorState from './DesignModeCursorState';
1515

1616
configure({ adapter: new Adapter() });
1717

18-
const intl = createIntl({
19-
locale: 'en',
20-
defaultLocale: 'en',
21-
messages: messages.en
22-
});
23-
2418
const defaultDimensions = new SceneDimensions(1, 1, 1, 1);
2519

2620
const defaultSceneProps = {
@@ -33,7 +27,7 @@ const defaultSceneProps = {
3327
customBackgroundDesignMode: false,
3428
startingX: 1,
3529
startingY: 2,
36-
characterDescriptionBuilder: new CharacterDescriptionBuilder(intl)
30+
characterDescriptionBuilder: new CharacterDescriptionBuilder()
3731
};
3832

3933
function createMountScene(props) {

0 commit comments

Comments
 (0)