Skip to content

Commit 88d973c

Browse files
committed
Actions refactoring.
1 parent f531c99 commit 88d973c

File tree

6 files changed

+75
-59
lines changed

6 files changed

+75
-59
lines changed

App/actions/index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as types from '../constants/ActionTypes';
2+
3+
4+
export const toggleOption = (optionType) => ({
5+
'type': optionType
6+
});
7+
8+
export const addDomainLock = (domain) => ({
9+
'type': types.ADD_DOMAIN_LOCK,
10+
domain
11+
});
12+
13+
export const removeDomainLock = (domain) => ({
14+
'type': types.REMOVE_DOMAIN_LOCK,
15+
domain
16+
});
17+
18+
export const addReservedName = (name) => ({
19+
'type': types.ADD_RESERVED_NAME,
20+
name
21+
});
22+
23+
export const removeReservedName = (name) => ({
24+
'type': types.REMOVE_RESERVED_NAME,
25+
name
26+
});
27+
28+
export const setUnicodeArrayThreshold = (threshold) => ({
29+
'type': types.SET_UNICODE_ARRAY_THRESHOLD,
30+
threshold
31+
});
32+
33+
export const setSourceMapMode = (mode) => ({
34+
'type': types.SET_SOURCEMAP_MODE,
35+
mode
36+
});
37+
38+
export const setSourceMapBaseUrl = (baseUrl) => ({
39+
'type': types.SET_SOURCEMAP_BASE_URL,
40+
baseUrl
41+
});
42+
43+
export const setSourceMapFileName = (fileName) => ({
44+
'type': types.SET_SOURCEMAP_FILE_NAME,
45+
fileName
46+
});

App/containers/Editor.js renamed to App/containers/EditorContainer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require('codemirror/lib/codemirror.css');
66
require('codemirror/mode/javascript/javascript');
77

88

9-
class Editor extends Component {
9+
export default class EditorContainer extends Component {
1010
constructor(props) {
1111
super(props);
1212
this.state = {
@@ -45,5 +45,3 @@ class Editor extends Component {
4545
}
4646

4747
}
48-
49-
export default Editor;

App/containers/EntryInput.js renamed to App/containers/EntryInputContainer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import { Form } from 'semantic-ui-react';
33

4-
class EntryInput extends React.Component {
4+
export default class EntryInputContainer extends React.Component {
55

66
static propTypes = {
77
label: React.PropTypes.string,
@@ -61,7 +61,6 @@ class EntryInput extends React.Component {
6161

6262
}
6363

64-
export default EntryInput;
6564

6665
const Labels = ({entries, onCloseClick}) =>
6766
<div className="ui labels">

App/containers/Options.js renamed to App/containers/OptionsContainer.js

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import {render} from 'react-dom';
55
import classNames from 'classnames';
66
import Dropzone from 'react-dropzone';
77

8-
import { Form } from 'stardust';
9-
import { Grid, Segment, Divider } from 'semantic-ui-react';
8+
import { Form, Grid, Segment, Divider } from 'semantic-ui-react';
109

11-
import * as types from '../constants/ActionTypes';
10+
import EntryInputContainer from '../containers/EntryInputContainer';
1211

13-
import EntryInput from '../containers/EntryInput';
12+
import * as types from '../constants/ActionTypes';
13+
import * as actions from '../actions/';
1414

1515

1616
export const SOURCEMAP_OFF = 'off'
@@ -24,72 +24,46 @@ const SOURCEMAP_OPTIONS = [
2424
];
2525

2626

27-
class Options extends React.Component {
27+
export default class OptionsContainer extends React.Component {
2828

2929
componentWillMount() {
3030
this.store = this.context.store;
3131
}
3232

3333
toggleOption(optionType) {
34-
this.store.dispatch({
35-
'type': optionType,
36-
});
34+
this.store.dispatch(actions.toggleOption(optionType));
3735
}
3836

3937
addDomainLock(domain) {
40-
this.store.dispatch({
41-
'type': types.ADD_DOMAIN_LOCK,
42-
domain,
43-
});
38+
this.store.dispatch(actions.addDomainLock(domain));
4439
}
4540

4641
removeDomainLock(domain) {
47-
this.store.dispatch({
48-
'type': types.REMOVE_DOMAIN_LOCK,
49-
domain,
50-
});
42+
this.store.dispatch(actions.removeDomainLock(domain));
5143
}
5244

5345
addReservedName(name) {
54-
this.store.dispatch({
55-
'type': types.ADD_RESERVED_NAME,
56-
name,
57-
});
46+
this.store.dispatch(actions.addReservedName(name));
5847
}
5948

6049
removeReservedName(name) {
61-
this.store.dispatch({
62-
'type': types.REMOVE_RESERVED_NAME,
63-
name,
64-
});
50+
this.store.dispatch(actions.removeReservedName(name));
6551
}
6652

6753
handleUnicodeThreshold(threshold) {
68-
this.store.dispatch({
69-
'type': types.SET_UNICODE_ARRAY_THRESHOLD,
70-
threshold,
71-
});
54+
this.store.dispatch(actions.setUnicodeArrayThreshold(threshold));
7255
}
7356

7457
handleSourceMapMode(mode) {
75-
this.store.dispatch({
76-
'type': types.SET_SOURCEMAP_MODE,
77-
mode,
78-
});
58+
this.store.dispatch(actions.setSourceMapMode(mode));
7959
}
8060

8161
handleSourceMapBaseUrl(baseUrl) {
82-
this.store.dispatch({
83-
'type': types.SET_SOURCEMAP_BASE_URL,
84-
baseUrl,
85-
});
62+
this.store.dispatch(actions.setSourceMapBaseUrl(baseUrl));
8663
}
8764

8865
handleSourceMapFileName(fileName) {
89-
this.store.dispatch({
90-
'type': types.SET_SOURCEMAP_FILE_NAME,
91-
fileName,
92-
});
66+
this.store.dispatch(actions.setSourceMapFileName(fileName));
9367
}
9468

9569
render() {
@@ -183,7 +157,7 @@ class Options extends React.Component {
183157
<Form.Select
184158
label='Sourcemaps'
185159
value={state.sourceMapMode}
186-
onChange={(event, value) => this.handleSourceMapMode(value) }
160+
onChange={(event, {value}) => this.handleSourceMapMode(value) }
187161
options={SOURCEMAP_OPTIONS} />
188162

189163
<Form.Input
@@ -196,8 +170,8 @@ class Options extends React.Component {
196170
<Form.Input
197171
label='Source Map File Name'
198172
disabled={!state.sourceMapSeparate}
199-
onChange={(event) => this.handleSourceMapFileName(event.target.value) }
200-
value={state.sourMapFileName}
173+
onBlur={(event) => this.handleSourceMapFileName(event.target.value) }
174+
defaultValue={state.sourMapFileName}
201175
placeholder='example' />
202176

203177
</Segment>
@@ -207,15 +181,15 @@ class Options extends React.Component {
207181
<Grid.Column>
208182
<Segment basic>
209183

210-
<EntryInput
184+
<EntryInputContainer
211185
label='Add a domain lock'
212186
actionAddEntryToState={::this.addDomainLock}
213187
actionRemoveEntryFromState={::this.removeDomainLock}
214188
placeholder="domain.com"
215189
entries={state.domainLock}
216190
buttonIcon="plus" />
217191

218-
<EntryInput
192+
<EntryInputContainer
219193
label='Reserved Names'
220194
actionAddEntryToState={::this.addReservedName}
221195
actionRemoveEntryFromState={::this.removeReservedName}
@@ -235,8 +209,6 @@ class Options extends React.Component {
235209

236210
}
237211

238-
Options.contextTypes = {
212+
OptionsContainer.contextTypes = {
239213
store: React.PropTypes.object
240214
};
241-
242-
export default Options;

App/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { Form, Grid, Segment, Divider } from 'semantic-ui-react';
1212
import classNames from 'classnames';
1313
import Dropzone from 'react-dropzone';
1414

15-
import Editor from './containers/Editor';
16-
import Options from './containers/Options';
15+
import EditorContainer from './containers/EditorContainer';
16+
import OptionsContainer from './containers/OptionsContainer';
1717

1818

1919
const middleware = [thunk];
@@ -111,7 +111,7 @@ class App extends React.Component {
111111
<Title active={this.state.selectedTabIndex == 2} onClick={() => this.onTabClick(2)}>Output</Title>
112112
</div>
113113
<Pane active={this.state.selectedTabIndex == 0}>
114-
<Editor onChange={this.onEditorChange} value={this.state.code} />
114+
<EditorContainer onChange={this.onEditorChange} value={this.state.code} />
115115
</Pane>
116116
<Pane active={this.state.selectedTabIndex == 1}>
117117
<Dropzone onDrop={this.onDrop} multiple={false}>
@@ -127,7 +127,7 @@ class App extends React.Component {
127127

128128
<div className="ui grid">
129129
<div className="column">
130-
<Options />
130+
<OptionsContainer />
131131
</div>
132132
</div>
133133

App/reducers/options.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as types from '../constants/ActionTypes';
2-
import {SOURCEMAP_SEPARATE} from '../containers/Options'
2+
3+
import {SOURCEMAP_SEPARATE} from '../containers/OptionsContainer'
34

45
const initialState = {
56
compactCode: true,
@@ -24,7 +25,7 @@ const initialState = {
2425
encodeUnicodeLiteralsEnabled: true,
2526

2627
sourceMapMode: 'off',
27-
sourceMapBaseUrl: 'http://',
28+
sourceMapBaseUrl: '',
2829
sourceMapFileName: '',
2930
sourceMapSeparate: false,
3031

0 commit comments

Comments
 (0)