Skip to content

Commit 7217aca

Browse files
committed
revert to before core
1 parent 827f230 commit 7217aca

File tree

21 files changed

+568
-15
lines changed

21 files changed

+568
-15
lines changed

lib/reducers/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
"use strict";
22
var redux_1 = require('redux');
3-
var coderoad_core_1 = require('coderoad-core');
3+
var alert_1 = require('./alert');
44
var checks_1 = require('./checks');
55
var devTools_toggle_1 = require('./devTools-toggle');
66
var dir_1 = require('./dir');
77
var hint_position_1 = require('./hint-position');
8+
var package_json_1 = require('./package-json');
9+
var page_1 = require('./page');
10+
var page_position_1 = require('./page-position');
811
var progress_1 = require('./progress');
12+
var route_1 = require('./route');
13+
var tasks_1 = require('./tasks');
914
var task_actions_1 = require('./task-actions');
1015
var task_position_1 = require('./task-position');
1116
var task_tests_1 = require('./task-tests');
1217
var test_run_1 = require('./test-run');
18+
var tutorial_1 = require('./tutorial');
19+
var tutorial_list_1 = require('./tutorial-list');
1320
var window_toggle_1 = require('./window-toggle');
1421
Object.defineProperty(exports, "__esModule", { value: true });
15-
exports.default = redux_1.combineReducers(Object.assign({}, {
16-
checks: checks_1.default, devToolsToggle: devTools_toggle_1.default, dir: dir_1.default, hintPosition: hint_position_1.default, progress: progress_1.default,
22+
exports.default = redux_1.combineReducers({
23+
alert: alert_1.default, checks: checks_1.default, devToolsToggle: devTools_toggle_1.default, dir: dir_1.default, hintPosition: hint_position_1.default,
24+
packageJson: package_json_1.default, page: page_1.default, pagePosition: page_position_1.default, progress: progress_1.default, route: route_1.default, tasks: tasks_1.default,
25+
tutorial: tutorial_1.default, tutorialList: tutorial_list_1.default,
1726
taskActions: task_actions_1.default, taskPosition: task_position_1.default, taskTests: task_tests_1.default, testRun: test_run_1.default, windowToggle: window_toggle_1.default
18-
}, coderoad_core_1.reducers));
27+
});

lib/reducers/package-json/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use strict";
2-
var _types_1 = require('../../actions/_types');
32
var path_1 = require('path');
43
var fs_1 = require('fs');
54
var exists_1 = require('../../services/exists');
5+
var _types_1 = require('../../actions/_types');
66
function packageJsonReducer(pj, action) {
77
if (pj === void 0) { pj = null; }
88
switch (action.type) {

lib/reducers/tutorial-list/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
2-
var _types_1 = require('../../actions/_types');
32
var check_1 = require('./check');
3+
var _types_1 = require('../../actions/_types');
44
function tutorialListReducer(tutorialList, action) {
55
if (tutorialList === void 0) { tutorialList = []; }
66
switch (action.type) {

lib/reducers/tutorial/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
2-
var _types_1 = require('../../actions/_types');
32
var path_1 = require('path');
43
var tutorial_config_1 = require('./tutorial-config');
4+
var _types_1 = require('../../actions/_types');
55
var _tutorial = {
66
name: null,
77
info: null,

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"atom": ">=1.0.0 <2.0.0"
3939
},
4040
"dependencies": {
41-
"coderoad-core": "^0.1.0",
4241
"highlights": "1.3.1",
4342
"marked": "0.3.5",
4443
"material-ui": "0.15.0",

src/reducers/alert/index.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import {
2+
ALERT_REPLAY, ALERT_TOGGLE, TUTORIAL_UPDATE,
3+
TEST_RESULT, COMPLETE_PAGE, COMPLETE_TUTORIAL
4+
} from '../../actions/_types';
5+
6+
const _alert: CR.Alert = {
7+
message: '',
8+
open: false,
9+
action: '',
10+
};
11+
const open = {
12+
open: true,
13+
action: 'pass',
14+
};
15+
16+
let current: CR.Alert = _alert;
17+
18+
function setAlert(options: Object, color?: string) {
19+
if (color) {
20+
let statusBarAlert = <HTMLElement>document.getElementsByClassName('cr-alert-replay')[0];
21+
statusBarAlert.style.color = color;
22+
}
23+
current = Object.assign({}, open, options);
24+
return current;
25+
}
26+
27+
export default function alertReducer(
28+
alert = _alert, action: Action
29+
): CR.Alert {
30+
switch (action.type) {
31+
32+
case ALERT_REPLAY:
33+
return setAlert(current);
34+
35+
case ALERT_TOGGLE:
36+
return action.payload.alert || _alert;
37+
38+
case TUTORIAL_UPDATE:
39+
return setAlert({
40+
message: `run \`npm install --save-dev ${action.payload.name}\``,
41+
action: 'note',
42+
duration: 4000,
43+
});
44+
45+
case TEST_RESULT:
46+
const result = action.payload.result;
47+
48+
switch (true) {
49+
// pass
50+
case result.pass && result.change > 0:
51+
return setAlert({
52+
message: result.msg,
53+
duration: result.duration || 1500,
54+
}, '#73C990');
55+
// Fail
56+
case result.pass === false && result.change < 1:
57+
return setAlert({
58+
message: result.msg,
59+
action: 'fail',
60+
duration: result.duration || 2500,
61+
}, '#FF4081');
62+
// Alert
63+
default:
64+
break;
65+
}
66+
return setAlert({
67+
message: result.msg,
68+
action: 'note',
69+
duration: result.duration || 2500,
70+
}, '#9DA5B4');
71+
72+
case COMPLETE_PAGE:
73+
return setAlert({
74+
message: `Page ${action.payload.pagePosition + 1} Complete`,
75+
});
76+
77+
case COMPLETE_TUTORIAL:
78+
return setAlert({
79+
message: 'Tutorial Complete',
80+
});
81+
82+
default:
83+
return alert;
84+
}
85+
}

src/reducers/index.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
import {combineReducers} from 'redux';
2-
import {reducers} from 'coderoad-core';
2+
// import {reducers} from 'coderoad-core';
33

4+
import alert from './alert';
45
import checks from './checks';
56
import devToolsToggle from './devTools-toggle';
67
import dir from './dir';
78
import hintPosition from './hint-position';
9+
import packageJson from './package-json';
10+
import page from './page';
11+
import pagePosition from './page-position';
812
import progress from './progress';
13+
import route from './route';
14+
import tasks from './tasks';
915
import taskActions from './task-actions';
1016
import taskPosition from './task-position';
1117
import taskTests from './task-tests';
1218
import testRun from './test-run';
19+
import tutorial from './tutorial';
20+
import tutorialList from './tutorial-list';
1321
import windowToggle from './window-toggle';
1422

15-
export default combineReducers(
16-
Object.assign({}, {
17-
checks, devToolsToggle, dir, hintPosition, progress,
18-
taskActions, taskPosition, taskTests, testRun, windowToggle
19-
}, reducers)
20-
);
23+
export default combineReducers({
24+
alert, checks, devToolsToggle, dir, hintPosition,
25+
packageJson, page, pagePosition, progress, route, tasks,
26+
tutorial, tutorialList,
27+
taskActions, taskPosition, taskTests, testRun, windowToggle
28+
});

src/reducers/package-json/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {join} from 'path';
2+
import {readFileSync} from 'fs';
3+
import {fileExists} from '../../services/exists';
4+
import {SETUP_PACKAGE} from '../../actions/_types';
5+
6+
export default function packageJsonReducer(
7+
pj = null, action: Action
8+
): PackageJson {
9+
switch (action.type) {
10+
11+
case SETUP_PACKAGE:
12+
const {dir} = action.payload;
13+
const pathToPackageJson = join(dir, 'package.json');
14+
if (fileExists(pathToPackageJson)) {
15+
return JSON.parse(readFileSync(pathToPackageJson, 'utf8'));
16+
}
17+
return null;
18+
19+
default:
20+
return pj;
21+
}
22+
}

src/reducers/page-position/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {
2+
PROGRESS_PAGE_POSITION_LOAD, PAGE_SET, PAGE_POSITION_SET
3+
} from '../../actions/_types';
4+
5+
export default function pagePositionReducer(
6+
pagePosition = 0, action: Action
7+
): CR.PagePosition {
8+
switch (action.type) {
9+
10+
case PROGRESS_PAGE_POSITION_LOAD:
11+
const pages = action.payload.progress.pages;
12+
const firstFail = pages.indexOf(false);
13+
return firstFail < 0 ? pages.length - 1 : firstFail;
14+
15+
case PAGE_SET:
16+
case PAGE_POSITION_SET:
17+
return action.payload.pagePosition;
18+
19+
default:
20+
return pagePosition;
21+
}
22+
}

src/reducers/page/index.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {PAGE_SET, COMPLETE_PAGE} from '../../actions/_types';
2+
// import {clearConsole} from '../../atom/editor';
3+
4+
const _page: CR.Page = {
5+
title: '',
6+
description: '',
7+
completed: false,
8+
};
9+
10+
export default function pageReducer(
11+
p = _page, action: Action
12+
): CR.Page {
13+
switch (action.type) {
14+
15+
case PAGE_SET:
16+
const {pagePosition, tutorial} = action.payload;
17+
const {title, description, onPageComplete, completed} = tutorial.pages[pagePosition];
18+
// clear dev console
19+
// clearConsole();
20+
return {
21+
title,
22+
description,
23+
onPageComplete,
24+
completed: completed || false
25+
};
26+
27+
case COMPLETE_PAGE:
28+
return Object.assign({}, p, { completed: true });
29+
30+
default:
31+
return p;
32+
}
33+
}

src/reducers/page/page.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// import {expect} from 'chai';
2+
//
3+
// import {reducer, initialState} from '../../../lib/_base';
4+
// import * as Action from '../../../lib/actions';
5+
//
6+
// xdescribe('Page: ', () => {
7+
//
8+
// describe('PAGE_SET', () => {
9+
// it('loads [0, 0] into store', () => {
10+
// const action: Action = Action.pageSet();
11+
// const nextState = reducer(initialState, action);
12+
// expect(nextState.getIn(['position', 'chapter'])).to.equal(0);
13+
// expect(nextState.getIn(['position', 'page'])).to.equal(0);
14+
// expect(nextState.getIn(['page', 'title'])).to.equal('Page 1');
15+
// });
16+
//
17+
// it('loads page [0,1] into store', () => {
18+
// const position: Tut.Position = { chapter: 0, page: 1, task: 0 };
19+
// const action: Action = Action.pageSet(position);
20+
// const nextState = reducer(initialState, action);
21+
// expect(nextState.getIn(['position', 'chapter'])).to.equal(0);
22+
// expect(nextState.getIn(['position', 'page'])).to.equal(1);
23+
// expect(nextState.getIn(['page', 'title'])).to.equal('Page 2');
24+
// });
25+
//
26+
// it('loads page [1,0] into store', () => {
27+
// const position: Tut.Position = { chapter: 1, page: 0, task: 0 };
28+
// const action: Action = Action.pageSet(position);
29+
// const nextState = reducer(initialState, action);
30+
// expect(nextState.getIn(['position', 'chapter'])).to.equal(1);
31+
// expect(nextState.getIn(['position', 'page'])).to.equal(0);
32+
// expect(nextState.getIn(['page', 'title'])).to.equal('Page 1');
33+
// });
34+
//
35+
// // it('loads the first task');
36+
// });
37+
// });

src/reducers/route/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {ROUTE_SET} from '../../actions/_types';
2+
3+
const _route = 'start';
4+
5+
export default function routeReducer(
6+
route = _route, action: Action
7+
): string {
8+
switch (action.type) {
9+
10+
case ROUTE_SET:
11+
return action.payload.route;
12+
13+
default:
14+
return route;
15+
}
16+
}

src/reducers/tasks/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {PAGE_SET} from '../../actions/_types';
2+
3+
const _tasks: CR.Task[] = [{
4+
actions: [],
5+
completed: false,
6+
description: '',
7+
hints: [],
8+
tests: [],
9+
}];
10+
11+
export default function tasksReducer(tasks = _tasks,
12+
action: Action): CR.Task[] {
13+
switch (action.type) {
14+
15+
case PAGE_SET:
16+
return action.payload.tasks;
17+
18+
default:
19+
return tasks;
20+
}
21+
}

src/reducers/tasks/tasks.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// import {expect} from 'chai';
2+
// import {reducer, initialState} from '../../../lib/_base';
3+
// import * as Action from '../../../lib/actions';
4+
//
5+
// xdescribe('Task Action: ', () => {
6+
//
7+
// describe('PAGE_SET', () => {
8+
// it('initializes the tasks for the page', () => {
9+
// const position: Tut.Position = { chapter: 0, page: 1, task: -1 };
10+
// const action: Action = Action.pageSet(position);
11+
// expect(reducer(initialState, action).get('tasks').size)
12+
// .to.be.greaterThan(0);
13+
// });
14+
// });
15+
//
16+
// describe('NEXT_TASK', () => {
17+
// // return TASK
18+
//
19+
// it('calls NEXT_TASK again if next task is already complete', () => {
20+
// const state = initialState.setIn(['progress', 'chapter', 0, 'page', 0, 'task', 0, 'completed'], true);
21+
// const action = Action.nextTask();
22+
// expect(state.get('tasks').size).to.equal(0);
23+
// const nextState = reducer(state, action);
24+
// expect(nextState.get('tasks').size).to.equal(2);
25+
// });
26+
//
27+
// // it('adds a single task watcher to the task watcher list');
28+
//
29+
// });
30+
//
31+
// });
32+
// // Task -> Page -> Chapter -> Tutorial

0 commit comments

Comments
 (0)