Skip to content

Commit 996a73e

Browse files
committed
Merge branch 'packageRefactor'
2 parents 4d3bdbc + f4b5f92 commit 996a73e

File tree

167 files changed

+1342
-1236
lines changed

Some content is hidden

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

167 files changed

+1342
-1236
lines changed

lib/actions/_types.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ exports.ALERT_TOGGLE = 'ALERT_TOGGLE';
44
exports.COMPLETE_CHAPTER = 'COMPLETE_CHAPTER';
55
exports.COMPLETE_PAGE = 'COMPLETE_PAGE';
66
exports.COMPLETE_TUTORIAL = 'COMPLETE_TUTORIAL';
7-
exports.GLOBALS_SET = 'GLOBALS_SET';
87
exports.HINT_POSITION_SET = 'HINT_POSITION_SET';
98
exports.HINT_SHOW = 'HINT_SHOW';
109
exports.PACKAGE_SET = 'PACKAGE_SET';
11-
exports.PAGE_NEXT = 'PAGE_NEXT';
1210
exports.PAGE_SET = 'PAGE_SET';
1311
exports.POSITION_SET = 'POSITION_SET';
12+
exports.PROGRESS_LOAD = 'PROGRESS_LOAD';
1413
exports.ROUTE_SET = 'ROUTE_SET';
1514
exports.SETUP_VERIFY = 'SETUP_VERIFY';
1615
exports.TEST_COMPLETE = 'TEST_COMPLETE';
1716
exports.TEST_RESULT = 'TEST_RESULT';
1817
exports.TEST_RUN = 'TEST_RUN';
18+
exports.TESTS_LOAD = 'TESTS_LOAD';
1919
exports.TUTORIAL_SET = 'TUTORIAL_SET';
2020
exports.TUTORIAL_UPDATE = 'TUTORIAL_UPDATE';
2121
exports.TUTORIALS_FIND = 'TUTORIALS_FIND';

lib/actions/alert.js

+9-2
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

-6
This file was deleted.

lib/actions/hint.js

+4-1
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

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +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;
9-
var globals_1 = require('./globals');
10-
exports.globalsSet = globals_1.globalsSet;
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;
1110
var hint_1 = require('./hint');
1211
exports.hintShow = hint_1.hintShow;
1312
exports.hintPositionSet = hint_1.hintPositionSet;
@@ -24,7 +23,7 @@ var test_1 = require('./test');
2423
exports.testRun = test_1.testRun;
2524
exports.testComplete = test_1.testComplete;
2625
exports.testResult = test_1.testResult;
26+
exports.testsLoad = test_1.testsLoad;
2727
var tutorial_1 = require('./tutorial');
2828
exports.tutorialsFind = tutorial_1.tutorialsFind;
29-
exports.tutorialUpdate = tutorial_1.tutorialUpdate;
3029
exports.tutorialSet = tutorial_1.tutorialSet;

lib/actions/page.js

+40-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,49 @@
11
"use strict";
22
var _types_1 = require('./_types');
3+
var index_1 = require('./index');
34
var store_1 = require('../store');
4-
var tutorial_package_1 = require('../services/tutorial-package');
5+
var _position = {
6+
chapter: 0,
7+
page: 0,
8+
};
59
function pageNext() {
6-
var position = store_1.store.getState().position;
7-
var nextPosition = tutorial_package_1.default.getNextPosition(position);
8-
return pageSet(nextPosition);
10+
var position = null;
11+
var _a = store_1.store.getState().position, page = _a.page, chapter = _a.chapter;
12+
var chapters = store_1.store.getState().tutorial.chapters;
13+
if (page < chapters[chapter].pages.length - 1) {
14+
position = {
15+
chapter: chapter,
16+
page: page + 1,
17+
};
18+
}
19+
else if (chapter < chapters.length - 1) {
20+
store_1.store.dispatch(index_1.completePage());
21+
position = {
22+
chapter: chapter + 1,
23+
page: 0,
24+
};
25+
}
26+
else {
27+
store_1.store.dispatch(index_1.completeTutorial());
28+
position = {
29+
chapter: chapter,
30+
page: page
31+
};
32+
}
33+
return { type: _types_1.PAGE_SET, payload: { position: position } };
934
}
1035
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' } };
36+
function pageSet(position) {
37+
if (position === void 0) { position = _position; }
38+
if (position.completed) {
39+
return {
40+
payload: { route: 'final' },
41+
type: _types_1.ROUTE_SET,
42+
};
1543
}
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 } };
44+
return {
45+
payload: { position: position },
46+
type: _types_1.PAGE_SET,
47+
};
2148
}
2249
exports.pageSet = pageSet;

lib/actions/position.js

+4-1
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

+12-2
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

+4-1
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

+8-1
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

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
"use strict";
22
var _types_1 = require('./_types');
3-
function tutorialSet() {
4-
return { type: _types_1.TUTORIAL_SET };
3+
function tutorialSet(name) {
4+
return {
5+
payload: { name: name },
6+
type: _types_1.TUTORIAL_SET,
7+
};
58
}
69
exports.tutorialSet = tutorialSet;
7-
function tutorialUpdate(name) {
8-
return { type: _types_1.TUTORIAL_UPDATE, payload: { name: name } };
9-
}
10-
exports.tutorialUpdate = tutorialUpdate;
1110
function tutorialsFind() {
1211
return { type: _types_1.TUTORIALS_FIND };
1312
}

lib/atom/editor.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,23 @@ 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
});
58-
return getEditor().then(function (editor) {
58+
return (getEditor().then(function insertWithEditor(editor) {
5959
editor.moveToBottom();
6060
editor.insertText(text, options);
6161
editor.insertNewline();
6262
editor.moveToBottom();
6363
editor.save();
6464
setCursorPosition(editor);
65-
});
65+
}));
6666
}
6767
exports.insert = insert;
68+
var cursor = /::\s?>/g;
6869
function setCursorPosition(editor) {
69-
editor.scan(/::>/g, function (match) {
70-
var start = match.range.start;
71-
match.replace('');
72-
editor.setCursorScreenPosition(start, { autoscroll: true });
70+
editor.scan(cursor, function (scanned) {
71+
editor.setCursorScreenPosition(scanned.range.start);
72+
scanned.replace('');
73+
scanned.stop();
7374
});
7475
}

lib/atom/main.js

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,20 @@
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');
55
var subscriptions_1 = require('./subscriptions');
66
var store_1 = require('../store');
77
var actions_1 = require('../actions');
8-
function setDir() {
9-
if (atom.project.rootDirectories.length > 0) {
10-
return atom.project.rootDirectories[0].path;
11-
}
12-
else {
13-
return null;
14-
}
15-
}
16-
function setWin() {
17-
return navigator.appVersion.indexOf('Win') > -1;
18-
}
198
var Main = (function () {
209
function Main() {
2110
polyfills_1.default();
22-
window.coderoad = {
23-
dir: setDir(),
24-
win: setWin()
25-
};
2611
store_1.store.dispatch(actions_1.setupVerify());
2712
this.root = mount_1.initRoot();
2813
}
2914
Main.prototype.activate = function () {
3015
atom.workspace.addRightPanel({
3116
item: this.root,
32-
priority: 0
17+
priority: 0,
3318
});
3419
subscriptions_1.onActivate();
3520
render_1.render(this.root);

lib/atom/subscriptions.js

+2-2
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/alert/index.js renamed to lib/components/Alert/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var Action = require('../../actions');
1919
var Snackbar_1 = require('material-ui/Snackbar');
2020
var classNames = require('classnames');
2121
var defaultAlert = {
22-
open: false,
2322
message: '',
23+
open: false,
2424
};
2525
var Alert = (function (_super) {
2626
__extends(Alert, _super);
@@ -30,12 +30,12 @@ var Alert = (function (_super) {
3030
Alert.prototype.render = function () {
3131
var _a = this.props, alert = _a.alert, alertToggle = _a.alertToggle;
3232
var action = alert.action, open = alert.open, message = alert.message, duration = alert.duration;
33-
return (React.createElement(Snackbar_1.default, {className: classNames('cr-alert', action), open: open || false, message: message || '', action: action, autoHideDuration: duration || 1500, onActionTouchTap: alertToggle, onRequestClose: alertToggle}));
33+
return (React.createElement(Snackbar_1.default, {className: classNames('cr-alert', action), open: open || false, message: message || '', action: action, autoHideDuration: duration || 2000, onActionTouchTap: alertToggle, onRequestClose: alertToggle}));
3434
};
3535
Alert = __decorate([
3636
react_redux_1.connect(null, function (dispatch) {
3737
return {
38-
alertToggle: function () { return dispatch(Action.alertToggle()); }
38+
alertToggle: function () { return dispatch(Action.alertToggle()); },
3939
};
4040
}),
4141
__metadata('design:paramtypes', [])

lib/components/app.js renamed to lib/components/App.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var App = (function (_super) {
3535
_super.apply(this, arguments);
3636
}
3737
App.prototype.render = function () {
38+
console.log(this.props.store);
3839
return (React.createElement("section", {className: 'cr', key: 'main', style: { height: height }}, React.createElement(index_1.AppMenu, __assign({}, this.props.store)), React.createElement(Routes_1.Routes, __assign({}, this.props.store)), React.createElement(index_1.Alert, __assign({}, this.props.store))));
3940
};
4041
App = __decorate([

lib/components/AppMenu/MenuLink.js

+1-1
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

+4-2
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;

0 commit comments

Comments
 (0)