Skip to content

Commit a06418e

Browse files
committed
refactor routes
1 parent a5d2d56 commit a06418e

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

lib/components/routes/routes.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,23 @@ var Routes = (function (_super) {
1111
function Routes() {
1212
_super.apply(this, arguments);
1313
}
14-
Routes.prototype.chooseRoute = function (state) {
15-
switch (state.route) {
14+
Routes.prototype.render = function () {
15+
var _a = this.props.state, page = _a.page, tasks = _a.tasks, taskPosition = _a.taskPosition, hintPosition = _a.hintPosition, editorActions = _a.editorActions, testRun = _a.testRun, log = _a.log, progress = _a.progress, position = _a.position, checks = _a.checks, tutorials = _a.tutorials, route = _a.route;
16+
switch (route) {
1617
case 'page':
17-
return React.createElement(_components_1.Page, {page: state.page, tasks: state.tasks, taskPosition: state.taskPosition, hintPosition: state.hintPosition, editorActions: state.editorActions, testRun: state.testRun, log: state.log});
18+
return React.createElement(_components_1.Page, {page: page, tasks: tasks, taskPosition: taskPosition, hintPosition: hintPosition, editorActions: editorActions, testRun: testRun});
1819
case 'progress':
19-
return React.createElement(_components_1.Progress, {progress: state.progress, position: state.position});
20+
return React.createElement(_components_1.Progress, {progress: progress, position: position});
2021
case 'start':
21-
return React.createElement(_components_1.Start, {checks: state.checks});
22+
return React.createElement(_components_1.Start, {checks: checks});
2223
case 'tutorials':
23-
return React.createElement(_components_1.Tutorials, {tutorials: state.tutorials});
24+
return React.createElement(_components_1.Tutorials, {tutorials: tutorials});
2425
case 'final':
2526
return React.createElement(_components_1.FinalPage, null);
2627
default:
2728
throw 'Error: Route not found.';
2829
}
2930
};
30-
Routes.prototype.render = function () {
31-
var state = this.props.state;
32-
return (React.createElement("div", null, this.chooseRoute(state)));
33-
};
3431
return Routes;
3532
}(React.Component));
3633
exports.Routes = Routes;

src/components/routes/routes.tsx

+14-21
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,28 @@ import * as React from 'react';
22
import {Page, Progress, Tutorials, Start, FinalPage} from '../_components';
33

44
export class Routes extends React.Component<{state: CR.State}, {}> {
5-
chooseRoute(state: CR.State) {
6-
switch (state.route) {
5+
render() {
6+
const {page, tasks, taskPosition, hintPosition, editorActions, testRun,
7+
log, progress, position, checks, tutorials, route} = this.props.state;
8+
switch (route) {
79
case 'page':
8-
return <Page page={state.page}
9-
tasks={state.tasks}
10-
taskPosition={state.taskPosition}
11-
hintPosition={state.hintPosition}
12-
editorActions={state.editorActions}
13-
testRun={state.testRun}
14-
log={state.log} />;
10+
return <Page page={page}
11+
tasks={tasks}
12+
taskPosition={taskPosition}
13+
hintPosition={hintPosition}
14+
editorActions={editorActions}
15+
testRun={testRun} />;
1516
case 'progress':
16-
return <Progress progress={state.progress}
17-
position={state.position} />;
17+
return <Progress progress={progress}
18+
position={position} />;
1819
case 'start':
19-
return <Start checks={state.checks} />;
20+
return <Start checks={checks} />;
2021
case 'tutorials':
21-
return <Tutorials tutorials={state.tutorials} />;
22+
return <Tutorials tutorials={tutorials} />;
2223
case 'final':
2324
return <FinalPage />;
2425
default:
2526
throw 'Error: Route not found.';
2627
}
2728
}
28-
render() {
29-
const state = this.props.state;
30-
return (
31-
<div>
32-
{this.chooseRoute(state)}
33-
</div>
34-
);
35-
}
3629
}

0 commit comments

Comments
 (0)