Skip to content

Commit 42fed98

Browse files
committed
refactor reducers into modules
1 parent 292c286 commit 42fed98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+404
-224
lines changed

lib/actions/_types.js

-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22
exports.COMPLETE_PAGE = 'COMPLETE_PAGE';
33
exports.COMPLETE_TUTORIAL = 'COMPLETE_TUTORIAL';
44
exports.DEVTOOLS_TOGGLE = 'DEVTOOLS_TOGGLE';
5-
exports.HINT_POSITION_SET = 'HINT_POSITION_SET';
65
exports.PAGE_SET = 'PAGE_SET';
76
exports.PROGRESS_LOAD = 'PROGRESS_LOAD';
87
exports.PROGRESS_PAGE_POSITION_LOAD = 'PROGRESS_PAGE_POSITION_LOAD';
9-
exports.TEST_SAVE = 'TEST_SAVE';
108
exports.SETUP_PACKAGE = 'SETUP_PACKAGE';
119
exports.SETUP_VERIFY = 'SETUP_VERIFY';
12-
exports.TEST_COMPLETE = 'TEST_COMPLETE';
13-
exports.TEST_RESULT = 'TEST_RESULT';
14-
exports.TEST_RUN = 'TEST_RUN';
1510
exports.TUTORIAL_SET = 'TUTORIAL_SET';
1611
exports.TUTORIAL_UPDATE = 'TUTORIAL_UPDATE';
1712
exports.TUTORIALS_FIND = 'TUTORIALS_FIND';

lib/actions/hint.js

-6
This file was deleted.

lib/actions/index.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@ exports.progressLoad = progress_1.progressLoad;
44
exports.completePage = progress_1.completePage;
55
exports.completeTutorial = progress_1.completeTutorial;
66
exports.progressPagePositionLoad = progress_1.progressPagePositionLoad;
7-
var hint_1 = require('./hint');
8-
exports.hintPositionSet = hint_1.hintPositionSet;
97
var page_1 = require('./page');
108
exports.pageSet = page_1.pageSet;
119
exports.pageNext = page_1.pageNext;
12-
var setup_1 = require('./setup');
13-
exports.setupVerify = setup_1.setupVerify;
14-
exports.setupPackage = setup_1.setupPackage;
15-
var test_1 = require('./test');
16-
exports.testRun = test_1.testRun;
17-
exports.testComplete = test_1.testComplete;
18-
exports.testResult = test_1.testResult;
19-
exports.testSave = test_1.testSave;
2010
var tutorial_1 = require('./tutorial');
2111
exports.tutorialsFind = tutorial_1.tutorialsFind;
2212
exports.tutorialSet = tutorial_1.tutorialSet;
@@ -29,3 +19,13 @@ exports.alertClose = actions_1.alertClose;
2919
exports.alertReplay = actions_1.alertReplay;
3020
var actions_2 = require('../modules/route/actions');
3121
exports.routeSet = actions_2.routeSet;
22+
var actions_3 = require('../modules/setup/actions');
23+
exports.setupVerify = actions_3.setupVerify;
24+
exports.setupPackage = actions_3.setupPackage;
25+
var actions_4 = require('../modules/hints/actions');
26+
exports.hintPositionSet = actions_4.hintPositionSet;
27+
var actions_5 = require('../modules/tests/actions');
28+
exports.testRun = actions_5.testRun;
29+
exports.testResult = actions_5.testResult;
30+
exports.testSave = actions_5.testSave;
31+
exports.testComplete = actions_5.testComplete;

lib/actions/page.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22
var _types_1 = require('./_types');
3-
var hint_1 = require('./hint');
4-
var actions_1 = require('../modules/route/actions');
3+
var index_1 = require('./index');
54
function pageNext() {
65
return function (dispatch, getState) {
76
var pagePosition = getState().pagePosition;
@@ -14,9 +13,9 @@ function pageSet(pagePosition) {
1413
return function (dispatch, getState) {
1514
var _a = getState(), dir = _a.dir, progress = _a.progress, tutorial = _a.tutorial, route = _a.route;
1615
if (pagePosition >= progress.pages.length) {
17-
return dispatch(actions_1.routeSet('final'));
16+
return dispatch(index_1.routeSet('final'));
1817
}
19-
dispatch(hint_1.hintPositionSet(0));
18+
dispatch(index_1.hintPositionSet(0));
2019
var tasks = tutorial.pages[pagePosition].tasks || [];
2120
dispatch({
2221
type: _types_1.PAGE_SET, payload: { dir: dir, pagePosition: pagePosition, tutorial: tutorial, progress: progress, tasks: tasks }

lib/actions/progress.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22
var _types_1 = require('./_types');
3-
var actions_1 = require('../modules/alert/actions');
4-
var test_1 = require('./test');
3+
var index_1 = require('./index');
54
function progressPagePositionLoad() {
65
return function (dispatch, getState) {
76
var progress = getState().progress;
@@ -14,7 +13,7 @@ function progressLoad() {
1413
var tutorial = getState().tutorial;
1514
dispatch({ type: _types_1.PROGRESS_LOAD, payload: { tutorial: tutorial } });
1615
dispatch(progressPagePositionLoad());
17-
dispatch(test_1.testRun());
16+
dispatch(index_1.testRun());
1817
};
1918
}
2019
exports.progressLoad = progressLoad;
@@ -28,7 +27,7 @@ function completePage(completed) {
2827
dispatch(completeTutorial());
2928
}
3029
else {
31-
dispatch(actions_1.alertOpen({
30+
dispatch(index_1.alertOpen({
3231
message: "Page " + (pagePosition + 1) + " Complete",
3332
action: 'PASS',
3433
}));
@@ -45,7 +44,7 @@ function completeTutorial(completed) {
4544
return function (dispatch, getState) {
4645
var tutorial = getState().tutorial;
4746
dispatch({ type: _types_1.COMPLETE_TUTORIAL, payload: { tutorial: tutorial, completed: completed } });
48-
dispatch(actions_1.alertOpen({
47+
dispatch(index_1.alertOpen({
4948
message: 'Tutorial Complete',
5049
action: 'PASS',
5150
}));

lib/actions/tutorial.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
"use strict";
22
var _types_1 = require('./_types');
3-
var progress_1 = require('./progress');
4-
var actions_1 = require('../modules/route/actions');
5-
var actions_2 = require('../modules/alert/actions');
3+
var index_1 = require('./index');
64
function tutorialSet(name) {
75
return function (dispatch, getState) {
86
var dir = getState().dir;
97
dispatch({ type: _types_1.TUTORIAL_SET, payload: { name: name, dir: dir } });
10-
dispatch(progress_1.progressLoad());
11-
dispatch(actions_1.routeSet('progress'));
8+
dispatch(index_1.progressLoad());
9+
dispatch(index_1.routeSet('progress'));
1210
};
1311
}
1412
exports.tutorialSet = tutorialSet;
@@ -20,7 +18,7 @@ function tutorialUpdate(name) {
2018
duration: 3000,
2119
};
2220
dispatch({ type: _types_1.TUTORIAL_UPDATE, payload: { name: name } });
23-
dispatch(actions_2.alertOpen(alert));
21+
dispatch(index_1.alertOpen(alert));
2422
};
2523
}
2624
exports.tutorialUpdate = tutorialUpdate;

lib/atom/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var root_1 = require('../components/root');
44
var polyfills_1 = require('../services/polyfills');
55
var subscriptions_1 = require('./subscriptions');
66
var store_1 = require('../store');
7-
var actions_1 = require('../actions');
7+
var actions_1 = require('../modules/setup/actions');
88
var Main = (function () {
99
function Main() {
1010
polyfills_1.default();

lib/components/Start/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var React = require('react');
3-
var Checks_1 = require('./Checks');
3+
var index_1 = require('../index');
44
var Welcome_1 = require('./Welcome');
55
var headerStyles = {
66
display: 'block',
@@ -12,7 +12,7 @@ exports.Start = function (_a) {
1212
var checks = _a.checks;
1313
return (React.createElement("section", {className: 'cr-start'}, React.createElement("div", {style: headerStyles}, checks.passed
1414
? React.createElement(Welcome_1.default, null)
15-
: React.createElement(Checks_1.default, {checks: checks}))));
15+
: React.createElement(index_1.Checks, {checks: checks}))));
1616
};
1717
Object.defineProperty(exports, "__esModule", { value: true });
1818
exports.default = exports.Start;

lib/components/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ var alert_1 = require('../modules/alert');
2121
exports.Alert = alert_1.Alert;
2222
var route_1 = require('../modules/route');
2323
exports.RouteButton = route_1.RouteButton;
24+
var setup_1 = require('../modules/setup');
25+
exports.Checks = setup_1.Checks;

lib/modules/hints/Hints/HintButton.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"use strict";
2+
var __extends = (this && this.__extends) || function (d, b) {
3+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4+
function __() { this.constructor = d; }
5+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6+
};
7+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11+
return c > 3 && r && Object.defineProperty(target, key, r), r;
12+
};
13+
var __metadata = (this && this.__metadata) || function (k, v) {
14+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
15+
};
16+
var React = require('react');
17+
var react_redux_1 = require('react-redux');
18+
var FlatButton_1 = require('material-ui/FlatButton');
19+
var actions_1 = require('../actions');
20+
var HintButton = (function (_super) {
21+
__extends(HintButton, _super);
22+
function HintButton() {
23+
_super.apply(this, arguments);
24+
}
25+
HintButton.prototype.render = function () {
26+
var _a = this.props, hintPosition = _a.hintPosition, hintsLength = _a.hintsLength, label = _a.label, type = _a.type, hintSet = _a.hintSet;
27+
switch (type) {
28+
case 'next':
29+
return (React.createElement(FlatButton_1.default, {label: label, disabled: hintPosition > hintsLength - 2, onTouchTap: hintSet.bind(this, hintPosition + 1)}));
30+
case 'prev':
31+
return (React.createElement(FlatButton_1.default, {label: label, disabled: hintPosition === 0, onTouchTap: hintSet.bind(this, hintPosition - 1)}));
32+
}
33+
};
34+
HintButton = __decorate([
35+
react_redux_1.connect(null, function (dispatch) {
36+
return {
37+
hintSet: function (position) { return dispatch(actions_1.hintPositionSet(position)); },
38+
};
39+
}),
40+
__metadata('design:paramtypes', [])
41+
], HintButton);
42+
return HintButton;
43+
}(React.Component));
44+
Object.defineProperty(exports, "__esModule", { value: true });
45+
exports.default = HintButton;

lib/modules/hints/Hints/index.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
var React = require('react');
3+
var Card_1 = require('material-ui/Card');
4+
var index_1 = require('../../../components/index');
5+
var HintButton_1 = require('./HintButton');
6+
var help_1 = require('material-ui/svg-icons/action/help');
7+
var styles = {
8+
position: 'relative',
9+
margin: '5px auto 10px',
10+
width: '360px',
11+
textAlign: 'center',
12+
};
13+
var Hints = function (_a) {
14+
var task = _a.task, hintPosition = _a.hintPosition;
15+
var hints = task && task.hints ? task.hints : null;
16+
if (hintPosition < 0 || !hints || !hints.length) {
17+
return null;
18+
}
19+
var hint = hints[hintPosition];
20+
return (React.createElement(Card_1.Card, {style: styles}, React.createElement(Card_1.CardHeader, {title: 'Hints', avatar: React.createElement(help_1.default, null), actAsExpander: true, showExpandableButton: true}), React.createElement(Card_1.CardText, {className: 'cr-task-hint', expandable: true}, React.createElement(index_1.Markdown, null, hint)), hints.length > 1
21+
? React.createElement(Card_1.CardActions, {style: { paddingBottom: '30px !important' }, expandable: true, className: 'cr-task-hints-actions'}, React.createElement(HintButton_1.default, {type: 'prev', label: 'Previous', hintPosition: hintPosition, hintsLength: hints.length}), React.createElement(HintButton_1.default, {type: 'next', label: 'Next', hintPosition: hintPosition, hintsLength: hints.length}))
22+
: null));
23+
};
24+
Object.defineProperty(exports, "__esModule", { value: true });
25+
exports.default = Hints;

lib/modules/hints/actions.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
var types_1 = require('./types');
3+
function hintPositionSet(hintPosition) {
4+
return { type: types_1.HINT_POSITION_SET, payload: { hintPosition: hintPosition } };
5+
}
6+
exports.hintPositionSet = hintPositionSet;

lib/modules/hints/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
var Hints_1 = require('./Hints');
3+
exports.Hints = Hints_1.default;
4+
var reducer_1 = require('./reducer');
5+
exports.reducer = reducer_1.default;

lib/reducers/hint-position/index.js renamed to lib/modules/hints/reducer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";
2-
var _types_1 = require('../../actions/_types');
2+
var types_1 = require('./types');
33
function hintPositionReducer(hintPosition, action) {
44
if (hintPosition === void 0) { hintPosition = 0; }
55
switch (action.type) {
6-
case _types_1.HINT_POSITION_SET:
6+
case types_1.HINT_POSITION_SET:
77
return action.payload.hintPosition;
88
default:
99
return hintPosition;

lib/modules/hints/types.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
exports.HINT_POSITION_SET = 'HINT_POSITION_SET';

lib/components/Start/Checks/index.js renamed to lib/modules/setup/Checks/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var React = require('react');
33
var SystemChecks_1 = require('./SystemChecks');
44
var SetupChecks_1 = require('./SetupChecks');
55
var InstallGuide_1 = require('./InstallGuide');
6-
var index_1 = require('../../index');
6+
var index_1 = require('../../../components/index');
77
var styles = {
88
margin: '5px',
99
padding: '10px',
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
"use strict";
2-
var _types_1 = require('./_types');
2+
var types_1 = require('./types');
33
function setupVerify() {
44
return function (dispatch, getState) {
55
dispatch(setupPackage());
66
var _a = getState(), dir = _a.dir, packageJson = _a.packageJson;
7-
dispatch({ type: _types_1.SETUP_VERIFY, payload: { dir: dir, packageJson: packageJson } });
7+
dispatch({ type: types_1.SETUP_VERIFY, payload: { dir: dir, packageJson: packageJson } });
88
};
99
}
1010
exports.setupVerify = setupVerify;
1111
function setupPackage() {
1212
return function (dispatch, getState) {
1313
var dir = getState().dir;
14-
dispatch({ type: _types_1.SETUP_PACKAGE, payload: { dir: dir } });
14+
dispatch({ type: types_1.SETUP_PACKAGE, payload: { dir: dir } });
1515
};
1616
}
1717
exports.setupPackage = setupPackage;

lib/modules/setup/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
var Checks_1 = require('./Checks');
3+
exports.Checks = Checks_1.default;
4+
var reducer_1 = require('./reducer');
5+
exports.reducer = reducer_1.default;

lib/reducers/checks/index.js renamed to lib/modules/setup/reducer.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
2-
var _types_1 = require('../../actions/_types');
3-
var verify_1 = require('./verify');
2+
var types_1 = require('./types');
3+
var verify_1 = require('./utils/verify');
44
var _checks = {
55
passed: false,
66
system: {
@@ -14,15 +14,15 @@ var _checks = {
1414
hasTutorial: false,
1515
}
1616
};
17-
function checksReducer(checks, action) {
17+
function checks(checks, action) {
1818
if (checks === void 0) { checks = _checks; }
1919
switch (action.type) {
20-
case _types_1.SETUP_VERIFY:
20+
case types_1.SETUP_VERIFY:
2121
var _a = action.payload, dir = _a.dir, packageJson = _a.packageJson;
2222
return verify_1.default(dir, packageJson);
2323
default:
2424
return checks;
2525
}
2626
}
2727
Object.defineProperty(exports, "__esModule", { value: true });
28-
exports.default = checksReducer;
28+
exports.default = checks;

lib/modules/setup/types.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict";
2+
exports.SETUP_PACKAGE = 'SETUP_PACKAGE';
3+
exports.SETUP_VERIFY = 'SETUP_VERIFY';

lib/reducers/checks/action-setup.js renamed to lib/modules/setup/utils/action-setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var path_1 = require('path');
3-
var editor_1 = require('../../atom/editor');
3+
var editor_1 = require('../../../atom/editor');
44
var packageData = "{\n \"name\": \"demo\",\n \"dependencies\": {\n \"coderoad-functional-school\": \"^0.2.2\"\n }\n}";
55
function createPackageJson(dir) {
66
var packagePath = path_1.join(dir, 'package.json');

lib/reducers/checks/action-system.js renamed to lib/modules/setup/utils/action-system.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use strict";
2-
var command_line_1 = require('../../services/command-line');
2+
var command_line_1 = require('../../../services/command-line');
33
function updateNpm() {
44
command_line_1.default('npm', 'update -g npm')
55
.then(function (res) {

lib/reducers/checks/check-system.js renamed to lib/modules/setup/utils/check-system.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use strict";
2-
var command_line_1 = require('../../services/command-line');
2+
var command_line_1 = require('../../../services/command-line');
33
function matchVersions(v) {
44
return v.match(/([0-9]+)\.([0-9]+)/);
55
}

lib/reducers/checks/verify.js renamed to lib/modules/setup/utils/verify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var check_system_1 = require('./check-system');
3-
var check_1 = require('../tutorial-list/check');
3+
var check_1 = require('../../../reducers/tutorial-list/check');
44
function allTrue(obj) {
55
return Object.values(obj).every(function (x) { return x === true; });
66
}

0 commit comments

Comments
 (0)