Skip to content

Commit 445bcc9

Browse files
committed
refactor services into actions
1 parent c91a79f commit 445bcc9

File tree

136 files changed

+802
-771
lines changed

Some content is hidden

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

136 files changed

+802
-771
lines changed

lib/actions/_types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ exports.PACKAGE_SET = 'PACKAGE_SET';
1010
exports.PAGE_NEXT = 'PAGE_NEXT';
1111
exports.PAGE_SET = 'PAGE_SET';
1212
exports.POSITION_SET = 'POSITION_SET';
13+
exports.PROGRESS_LOAD = 'PROGRESS_LOAD';
1314
exports.ROUTE_SET = 'ROUTE_SET';
1415
exports.SETUP_VERIFY = 'SETUP_VERIFY';
1516
exports.TEST_COMPLETE = 'TEST_COMPLETE';
1617
exports.TEST_RESULT = 'TEST_RESULT';
1718
exports.TEST_RUN = 'TEST_RUN';
19+
exports.TESTS_LOAD = 'TESTS_LOAD';
1820
exports.TUTORIAL_SET = 'TUTORIAL_SET';
1921
exports.TUTORIAL_UPDATE = 'TUTORIAL_UPDATE';
2022
exports.TUTORIALS_FIND = 'TUTORIALS_FIND';

lib/actions/alert.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ var _types_1 = require('./_types');
44
function alertToggle(alert) {
55
var isOpen = store_1.store.getState().alert.open;
66
if (!alert) {
7-
alert = { message: '', action: '', open: false };
7+
alert = {
8+
action: '',
9+
message: '',
10+
open: false,
11+
};
812
}
913
else {
1014
alert = Object.assign({}, { open: !isOpen }, alert);
1115
}
12-
return { type: _types_1.ALERT_TOGGLE, payload: { alert: alert } };
16+
return {
17+
payload: { alert: alert },
18+
type: _types_1.ALERT_TOGGLE,
19+
};
1320
}
1421
exports.alertToggle = alertToggle;
1522
function alertReplay() {

lib/actions/globals.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/actions/hint.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"use strict";
22
var _types_1 = require('./_types');
33
function hintPositionSet(hintPosition) {
4-
return { type: _types_1.HINT_POSITION_SET, payload: { hintPosition: hintPosition } };
4+
return {
5+
payload: { hintPosition: hintPosition },
6+
type: _types_1.HINT_POSITION_SET,
7+
};
58
}
69
exports.hintPositionSet = hintPositionSet;
710
function hintShow() {

lib/actions/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
var alert_1 = require('./alert');
33
exports.alertToggle = alert_1.alertToggle;
44
exports.alertReplay = alert_1.alertReplay;
5-
var complete_1 = require('./complete');
6-
exports.completePage = complete_1.completePage;
7-
exports.completeChapter = complete_1.completeChapter;
8-
exports.completeTutorial = complete_1.completeTutorial;
5+
var progress_1 = require('./progress');
6+
exports.progressLoad = progress_1.progressLoad;
7+
exports.completePage = progress_1.completePage;
8+
exports.completeChapter = progress_1.completeChapter;
9+
exports.completeTutorial = progress_1.completeTutorial;
910
var hint_1 = require('./hint');
1011
exports.hintShow = hint_1.hintShow;
1112
exports.hintPositionSet = hint_1.hintPositionSet;
@@ -22,6 +23,7 @@ var test_1 = require('./test');
2223
exports.testRun = test_1.testRun;
2324
exports.testComplete = test_1.testComplete;
2425
exports.testResult = test_1.testResult;
26+
exports.testsLoad = test_1.testsLoad;
2527
var tutorial_1 = require('./tutorial');
2628
exports.tutorialsFind = tutorial_1.tutorialsFind;
2729
exports.tutorialSet = tutorial_1.tutorialSet;

lib/actions/page.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
"use strict";
22
var _types_1 = require('./_types');
33
var store_1 = require('../store');
4-
var tutorial_package_1 = require('../services/tutorial-package');
54
function pageNext() {
65
var position = store_1.store.getState().position;
7-
var nextPosition = tutorial_package_1.default.getNextPosition(position);
8-
return pageSet(nextPosition);
6+
return { type: _types_1.PAGE_NEXT, payload: { position: position } };
97
}
108
exports.pageNext = pageNext;
11-
function pageSet(selectedPosition) {
12-
if (selectedPosition === void 0) { selectedPosition = { chapter: 0, page: 0 }; }
13-
if (selectedPosition.completed) {
14-
return { type: _types_1.ROUTE_SET, payload: { route: 'final' } };
9+
function pageSet(position) {
10+
if (position === void 0) { position = { chapter: 0, page: 0 }; }
11+
if (position.completed) {
12+
return {
13+
payload: { route: 'final' },
14+
type: _types_1.ROUTE_SET,
15+
};
1516
}
16-
var page = tutorial_package_1.default.getPage(selectedPosition);
17-
var tasks = tutorial_package_1.default.getTasks(selectedPosition);
18-
var taskTests = [].concat.apply([], tasks.map(function (task) { return task.tests || []; }));
19-
var actions = tasks.map(function (task) { return task.actions || []; });
20-
return { type: _types_1.PAGE_SET, payload: { page: page, tasks: tasks, position: selectedPosition, taskTests: taskTests, actions: actions } };
17+
return {
18+
payload: { position: position },
19+
type: _types_1.PAGE_SET,
20+
};
2121
}
2222
exports.pageSet = pageSet;

lib/actions/position.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"use strict";
22
var _types_1 = require('./_types');
33
function positionSet(position) {
4-
return { type: _types_1.POSITION_SET, payload: { position: position } };
4+
return {
5+
payload: { position: position },
6+
type: _types_1.POSITION_SET,
7+
};
58
}
69
exports.positionSet = positionSet;

lib/actions/complete.js renamed to lib/actions/progress.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
"use strict";
22
var _types_1 = require('./_types');
33
var store_1 = require('../store');
4+
function progressLoad() {
5+
return { type: _types_1.PROGRESS_LOAD };
6+
}
7+
exports.progressLoad = progressLoad;
48
function completePage() {
59
var position = store_1.store.getState().position;
610
var pageLength = store_1.store.getState().progress.chapters[position.chapter].pages.length;
711
if (position.page >= pageLength - 1) {
812
return completeChapter();
913
}
10-
return { type: _types_1.COMPLETE_PAGE, payload: { position: position } };
14+
return {
15+
payload: { position: position },
16+
type: _types_1.COMPLETE_PAGE,
17+
};
1118
}
1219
exports.completePage = completePage;
1320
function completeChapter() {
@@ -16,7 +23,10 @@ function completeChapter() {
1623
if (chapter >= chapterLength - 1) {
1724
return completeTutorial();
1825
}
19-
return { type: _types_1.COMPLETE_CHAPTER, payload: { chapter: chapter } };
26+
return {
27+
payload: { chapter: chapter },
28+
type: _types_1.COMPLETE_CHAPTER,
29+
};
2030
}
2131
exports.completeChapter = completeChapter;
2232
function completeTutorial() {

lib/actions/route.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ function setRoute(route) {
1010
store_1.store.dispatch(tutorial_1.tutorialsFind());
1111
}
1212
previous = route;
13-
return { type: _types_1.ROUTE_SET, payload: { route: route } };
13+
return {
14+
payload: { route: route },
15+
type: _types_1.ROUTE_SET,
16+
};
1417
}
1518
}
1619
exports.setRoute = setRoute;

lib/actions/test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ function testRun() {
77
exports.testRun = testRun;
88
function testResult(result) {
99
var actions = store_1.store.getState().editorActions;
10-
return { type: _types_1.TEST_RESULT, payload: { result: result, actions: actions } };
10+
return {
11+
payload: { result: result, actions: actions },
12+
type: _types_1.TEST_RESULT,
13+
};
1114
}
1215
exports.testResult = testResult;
1316
function testComplete() {
1417
return { type: _types_1.TEST_COMPLETE };
1518
}
1619
exports.testComplete = testComplete;
20+
function testsLoad() {
21+
return { type: _types_1.TESTS_LOAD };
22+
}
23+
exports.testsLoad = testsLoad;

lib/actions/tutorial.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"use strict";
22
var _types_1 = require('./_types');
33
function tutorialSet(name) {
4-
return { type: _types_1.TUTORIAL_SET, payload: { name: name } };
4+
return {
5+
payload: { name: name },
6+
type: _types_1.TUTORIAL_SET,
7+
};
58
}
69
exports.tutorialSet = tutorialSet;
710
function tutorialsFind() {

lib/atom/editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ exports.set = set;
5353
function insert(text, options) {
5454
if (options === void 0) { options = {}; }
5555
options = Object.assign(options, {
56-
autoIndent: true
56+
autoIndent: true,
5757
});
5858
return getEditor().then(function (editor) {
5959
editor.moveToBottom();

lib/atom/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
"use strict";
22
var render_1 = require('../components/render');
33
var mount_1 = require('../components/mount');
44
var polyfills_1 = require('../services/polyfills');
@@ -21,15 +21,15 @@ var Main = (function () {
2121
polyfills_1.default();
2222
window.coderoad = {
2323
dir: setDir(),
24-
win: setWin()
24+
win: setWin(),
2525
};
2626
store_1.store.dispatch(actions_1.setupVerify());
2727
this.root = mount_1.initRoot();
2828
}
2929
Main.prototype.activate = function () {
3030
atom.workspace.addRightPanel({
3131
item: this.root,
32-
priority: 0
32+
priority: 0,
3333
});
3434
subscriptions_1.onActivate();
3535
render_1.render(this.root);

lib/atom/subscriptions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var subscriptions = null;
77
function onActivate() {
88
subscriptions = new CompositeDisposable;
99
subscriptions.add(atom.commands.add('atom-workspace', {
10-
'cr-viewer:toggle': mount_1.togglePanel
10+
'cr-viewer:toggle': mount_1.togglePanel,
1111
}));
1212
atom.workspace.observeTextEditors(function (editor) {
1313
subscriptions.add(editor.onDidSave(function () {
@@ -19,7 +19,7 @@ function onActivate() {
1919
if (store_1.store.getState().route === 'page') {
2020
store_1.store.dispatch(actions_1.testRun());
2121
}
22-
})
22+
}),
2323
}));
2424
return subscriptions;
2525
}

lib/components/AppMenu/MenuLink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var MenuLink = (function (_super) {
2929
MenuLink = __decorate([
3030
react_redux_1.connect(null, function (dispatch) {
3131
return {
32-
routeTo: function (route) { return dispatch(actions_1.setRoute(route)); }
32+
routeTo: function (route) { return dispatch(actions_1.setRoute(route)); },
3333
};
3434
}),
3535
__metadata('design:paramtypes', [])

lib/components/AppMenu/issuesLink.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"use strict";
22
var React = require('react');
33
var MenuItem_1 = require('material-ui/MenuItem');
4+
var store_1 = require('../../store');
45
function issuesLink() {
5-
if (!window.coderoad.issuesPath) {
6+
var tutorial = store_1.store.getState().tutorial;
7+
if (!tutorial || !tutorial.config || !tutorial.config.issuesPath) {
68
return null;
79
}
8-
return (React.createElement(MenuItem_1.default, {key: 'issue', className: 'link'}, React.createElement("a", {href: window.coderoad.issuesPath}, "post issue")));
10+
return (React.createElement(MenuItem_1.default, {key: 'issue', className: 'link'}, React.createElement("a", {href: tutorial.config.issuesPath}, "post issue")));
911
}
1012
exports.issuesLink = issuesLink;

lib/components/AppMenu/menuRight.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ var Quit_1 = require('./Quit');
66
var issuesLink_1 = require('./issuesLink');
77
var menuIconRight_1 = require('./menuIconRight');
88
var menuRightRouteOptions_1 = require('./menuRightRouteOptions');
9-
var origin = { horizontal: 'right', vertical: 'top' };
9+
var origin = {
10+
horizontal: 'right',
11+
vertical: 'top',
12+
};
1013
function menuRight(route) {
1114
return (React.createElement(IconMenu_1.default, {iconButtonElement: menuIconRight_1.menuIconRight(), targetOrigin: origin, anchorOrigin: origin}, menuRightRouteOptions_1.menuRightRouteOptions(route), issuesLink_1.issuesLink(), React.createElement(Divider_1.default, null), React.createElement(Quit_1.Quit, null)));
1215
}

lib/components/Common/RouteButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var RouteButton = (function (_super) {
2929
RouteButton = __decorate([
3030
react_redux_1.connect(null, function (dispatch) {
3131
return {
32-
routeTo: function (route) { return dispatch(actions_1.setRoute(route)); }
32+
routeTo: function (route) { return dispatch(actions_1.setRoute(route)); },
3333
};
3434
}),
3535
__metadata('design:paramtypes', [])

lib/components/Page/EditPage.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
var React = require('react');
33
var path = require('path');
44
var mode_edit_1 = require('material-ui/svg-icons/editor/mode-edit');
5-
var editStyle = { position: 'absolute', top: '10px', right: '10px' };
5+
var editStyle = {
6+
position: 'absolute',
7+
top: '10px',
8+
right: '10px',
9+
};
610
exports.EditPage = function (_a) {
7-
var editPath = _a.editPath;
8-
if (editPath && window.coderoad.edit) {
9-
var repoPath = path.join(window.coderoad.repo, 'edit', 'master', editPath);
11+
var tutorial = _a.tutorial;
12+
if (tutorial && tutorial.edit && tutorial.repo) {
13+
var repoPath = path.join(tutorial.repo, 'edit', 'master', tutorial.repo);
1014
return (React.createElement("a", {href: repoPath}, React.createElement(mode_edit_1.default, {style: editStyle})));
1115
}
1216
};

lib/components/Page/PageToolbar/Continue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Continue = (function (_super) {
2828
Continue = __decorate([
2929
react_redux_1.connect(null, function (dispatch, state) {
3030
return {
31-
callNextPage: function () { return dispatch(actions_1.pageNext()); }
31+
callNextPage: function () { return dispatch(actions_1.pageNext()); },
3232
};
3333
}),
3434
__metadata('design:paramtypes', [])

lib/components/Page/hints/HintButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var HintButton = (function (_super) {
3434
HintButton = __decorate([
3535
react_redux_1.connect(null, function (dispatch, state) {
3636
return {
37-
hintSet: function (position) { return dispatch(actions_1.hintPositionSet(position)); }
37+
hintSet: function (position) { return dispatch(actions_1.hintPositionSet(position)); },
3838
};
3939
}),
4040
__metadata('design:paramtypes', [])

lib/components/Page/tasks/Task.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
"use strict";
2-
var __assign = (this && this.__assign) || Object.assign || function(t) {
3-
for (var s, i = 1, n = arguments.length; i < n; i++) {
4-
s = arguments[i];
5-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6-
t[p] = s[p];
7-
}
8-
return t;
9-
};
10-
var _this = this;
112
var React = require('react');
123
var index_1 = require('../../index');
134
var TaskCheckbox_1 = require('./TaskCheckbox');
145
var List_1 = require('material-ui/List');
156
exports.Task = function (_a) {
167
var task = _a.task, taskPosition = _a.taskPosition, index = _a.index, testRun = _a.testRun;
178
var isCompleted = index < taskPosition;
18-
return (React.createElement(List_1.ListItem, {key: index, className: 'cr-task', style: { backgroundColor: isCompleted ? '#c8e6c9' : 'inherit' }}, React.createElement(TaskCheckbox_1.TaskCheckbox, __assign({}, _this.props)), React.createElement("span", {className: 'cr-task-index'}, index + 1, "."), React.createElement("div", {className: 'cr-task-description'}, React.createElement(index_1.Markdown, null, task.description))));
9+
return (React.createElement(List_1.ListItem, {key: index, className: 'cr-task', style: { backgroundColor: isCompleted ? '#c8e6c9' : 'inherit' }}, React.createElement(TaskCheckbox_1.TaskCheckbox, {taskPosition: taskPosition, index: index, testRun: testRun}), React.createElement("span", {className: 'cr-task-index'}, index + 1, "."), React.createElement("div", {className: 'cr-task-description'}, React.createElement(index_1.Markdown, null, task.description))));
1910
};

lib/components/Page/tasks/TaskCheckbox.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var indeterminate_check_box_1 = require('material-ui/svg-icons/toggle/indetermin
77
exports.TaskCheckbox = function (_a) {
88
var index = _a.index, taskPosition = _a.taskPosition, testRun = _a.testRun;
99
var icon = null;
10+
console.log(index, taskPosition, testRun);
1011
if (index < taskPosition) {
1112
icon = React.createElement(check_box_1.default, {color: colors_1.green500});
1213
}

lib/components/Page/tasks/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
"use strict";
2-
var __assign = (this && this.__assign) || Object.assign || function(t) {
3-
for (var s, i = 1, n = arguments.length; i < n; i++) {
4-
s = arguments[i];
5-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6-
t[p] = s[p];
7-
}
8-
return t;
9-
};
10-
var _this = this;
112
var React = require('react');
123
var List_1 = require('material-ui/List');
134
var Card_1 = require('material-ui/Card');
@@ -19,5 +10,5 @@ function visibleTasks(tasks, taskPosition) {
1910
exports.Tasks = function (_a) {
2011
var tasks = _a.tasks, taskPosition = _a.taskPosition, testRun = _a.testRun;
2112
var visTasks = visibleTasks(tasks, taskPosition);
22-
return (React.createElement(Card_1.Card, {className: 'cr-tasks'}, React.createElement(List_1.List, null, React.createElement(Subheader_1.default, null, "Tasks"), visTasks.map(function (task, index) { return (React.createElement(Task_1.Task, __assign({key: index, index: index, task: task}, _this.props))); }))));
13+
return (React.createElement(Card_1.Card, {className: 'cr-tasks'}, React.createElement(List_1.List, null, React.createElement(Subheader_1.default, null, "Tasks"), visTasks.map(function (task, index) { return (React.createElement(Task_1.Task, {key: index, index: index, task: task, taskPosition: taskPosition, testRun: testRun})); }))));
2314
};

lib/components/Progress/ProgressPage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var ProgressPage = (function (_super) {
5656
return {
5757
selectPage: function (position) {
5858
dispatch(actions_1.pageSet(position));
59+
dispatch(actions_1.testsLoad());
5960
dispatch(actions_1.setRoute('page'));
6061
}
6162
};

0 commit comments

Comments
 (0)