Skip to content

Commit 87f8460

Browse files
committed
refactor SET_PACKAGE & PAGE_POSITION_LOAD
1 parent 216a791 commit 87f8460

File tree

16 files changed

+51
-48
lines changed

16 files changed

+51
-48
lines changed

lib/actions/_types.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ exports.COMPLETE_TUTORIAL = 'COMPLETE_TUTORIAL';
66
exports.DEVTOOLS_TOGGLE = 'DEVTOOLS_TOGGLE';
77
exports.HINT_POSITION_SET = 'HINT_POSITION_SET';
88
exports.HINT_SHOW = 'HINT_SHOW';
9-
exports.PACKAGE_SET = 'PACKAGE_SET';
109
exports.PAGE_SET = 'PAGE_SET';
11-
exports.PAGE_POSITION_LOAD = 'POSITION_LOAD';
1210
exports.PAGE_POSITION_SET = 'POSITION_SET';
1311
exports.PROGRESS_LOAD = 'PROGRESS_LOAD';
12+
exports.PROGRESS_PAGE_POSITION_LOAD = 'PROGRESS_PAGE_POSITION_LOAD';
1413
exports.QUIT = 'QUIT';
1514
exports.ROUTE_SET = 'ROUTE_SET';
1615
exports.TEST_SAVE = 'TEST_SAVE';
16+
exports.SETUP_PACKAGE = 'SETUP_PACKAGE';
1717
exports.SETUP_VERIFY = 'SETUP_VERIFY';
1818
exports.TEST_COMPLETE = 'TEST_COMPLETE';
1919
exports.TEST_RESULT = 'TEST_RESULT';

lib/actions/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ var progress_1 = require('./progress');
66
exports.progressLoad = progress_1.progressLoad;
77
exports.completePage = progress_1.completePage;
88
exports.completeTutorial = progress_1.completeTutorial;
9+
exports.progressPagePositionLoad = progress_1.progressPagePositionLoad;
910
var hint_1 = require('./hint');
1011
exports.hintShow = hint_1.hintShow;
1112
exports.hintPositionSet = hint_1.hintPositionSet;
1213
var page_1 = require('./page');
1314
exports.pageSet = page_1.pageSet;
1415
exports.pageNext = page_1.pageNext;
15-
exports.pagePositionLoad = page_1.pagePositionLoad;
1616
exports.pagePositionSet = page_1.pagePositionSet;
1717
var route_1 = require('./route');
1818
exports.routeSet = route_1.routeSet;
1919
var setup_1 = require('./setup');
2020
exports.setupVerify = setup_1.setupVerify;
21+
exports.setupPackage = setup_1.setupPackage;
2122
var test_1 = require('./test');
2223
exports.testRun = test_1.testRun;
2324
exports.testComplete = test_1.testComplete;

lib/actions/page.js

-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ function pageSet(pagePosition) {
2929
};
3030
}
3131
exports.pageSet = pageSet;
32-
function pagePositionLoad() {
33-
return function (dispatch, getState) {
34-
var progress = getState().progress;
35-
dispatch({ type: _types_1.PAGE_POSITION_LOAD, payload: { progress: progress } });
36-
};
37-
}
38-
exports.pagePositionLoad = pagePositionLoad;
3932
function pagePositionSet(pagePosition) {
4033
return { type: _types_1.PAGE_POSITION_SET, payload: { pagePosition: pagePosition } };
4134
}

lib/actions/progress.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
"use strict";
22
var _types_1 = require('./_types');
3-
var page_1 = require('./page');
3+
function progressPagePositionLoad() {
4+
return function (dispatch, getState) {
5+
var progress = getState().progress;
6+
dispatch({ type: _types_1.PROGRESS_PAGE_POSITION_LOAD, payload: { progress: progress } });
7+
};
8+
}
9+
exports.progressPagePositionLoad = progressPagePositionLoad;
410
function progressLoad() {
511
return function (dispatch, getState) {
612
var tutorial = getState().tutorial;
713
dispatch({ type: _types_1.PROGRESS_LOAD, payload: { tutorial: tutorial } });
8-
dispatch(page_1.pagePositionLoad());
14+
dispatch(progressPagePositionLoad());
915
};
1016
}
1117
exports.progressLoad = progressLoad;

lib/actions/setup.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
"use strict";
22
var _types_1 = require('./_types');
3-
var package_1 = require('./package');
43
function setupVerify() {
54
return function (dispatch, getState) {
6-
dispatch(package_1.packageSet());
5+
dispatch(setupPackage());
76
var _a = getState(), dir = _a.dir, packageJson = _a.packageJson;
87
dispatch({ type: _types_1.SETUP_VERIFY, payload: { dir: dir, packageJson: packageJson } });
98
};
109
}
1110
exports.setupVerify = setupVerify;
11+
function setupPackage() {
12+
return function (dispatch, getState) {
13+
var dir = getState().dir;
14+
dispatch({ type: _types_1.SETUP_PACKAGE, payload: { dir: dir } });
15+
};
16+
}
17+
exports.setupPackage = setupPackage;

lib/reducers/package-json/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var exists_1 = require('../../services/exists');
66
function packageJsonReducer(pj, action) {
77
if (pj === void 0) { pj = null; }
88
switch (action.type) {
9-
case _types_1.PACKAGE_SET:
9+
case _types_1.SETUP_PACKAGE:
1010
var dir = action.payload.dir;
1111
var pathToPackageJson = path_1.join(dir, 'package.json');
1212
if (exists_1.fileExists(pathToPackageJson)) {

lib/reducers/page-position/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var _types_1 = require('../../actions/_types');
33
function pagePositionReducer(pagePosition, action) {
44
if (pagePosition === void 0) { pagePosition = 0; }
55
switch (action.type) {
6-
case _types_1.PAGE_POSITION_LOAD:
6+
case _types_1.PROGRESS_PAGE_POSITION_LOAD:
77
var pages = action.payload.progress.pages;
88
var firstFail = pages.indexOf(false);
99
return firstFail < 0 ? pages.length - 1 : firstFail;

src/actions/_types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ export const COMPLETE_TUTORIAL = 'COMPLETE_TUTORIAL';
55
export const DEVTOOLS_TOGGLE = 'DEVTOOLS_TOGGLE';
66
export const HINT_POSITION_SET = 'HINT_POSITION_SET';
77
export const HINT_SHOW = 'HINT_SHOW';
8-
export const PACKAGE_SET = 'PACKAGE_SET';
98
export const PAGE_SET = 'PAGE_SET';
10-
export const PAGE_POSITION_LOAD = 'POSITION_LOAD';
119
export const PAGE_POSITION_SET = 'POSITION_SET';
1210
export const PROGRESS_LOAD = 'PROGRESS_LOAD';
11+
export const PROGRESS_PAGE_POSITION_LOAD = 'PROGRESS_PAGE_POSITION_LOAD';
1312
export const QUIT = 'QUIT';
1413
export const ROUTE_SET = 'ROUTE_SET';
1514
export const TEST_SAVE = 'TEST_SAVE';
15+
export const SETUP_PACKAGE = 'SETUP_PACKAGE';
1616
export const SETUP_VERIFY = 'SETUP_VERIFY';
1717
export const TEST_COMPLETE = 'TEST_COMPLETE';
1818
export const TEST_RESULT = 'TEST_RESULT';

src/actions/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
export {alertToggle, alertReplay} from './alert';
22
export {
3-
progressLoad, completePage, completeTutorial
3+
progressLoad, completePage, completeTutorial,
4+
progressPagePositionLoad
45
} from './progress';
56
export {hintShow, hintPositionSet} from './hint';
6-
export {pageSet, pageNext, pagePositionLoad, pagePositionSet} from './page';
7+
export {pageSet, pageNext, pagePositionSet} from './page';
78
export {routeSet} from './route';
8-
export {setupVerify} from './setup';
9+
export {setupVerify, setupPackage} from './setup';
910
export {
1011
testRun, testComplete, testResult, testSave
1112
} from './test';

src/actions/package.ts

-8
This file was deleted.

src/actions/page.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
ROUTE_SET, PAGE_SET, PAGE_POSITION_SET, PAGE_POSITION_LOAD
2+
ROUTE_SET, PAGE_SET, PAGE_POSITION_SET
33
} from './_types';
44
import configTaskTests from './config-task-tests';
55

@@ -32,13 +32,6 @@ export function pageSet(pagePosition = 0): ReduxThunk.ThunkInterface {
3232
};
3333
}
3434

35-
export function pagePositionLoad(): ReduxThunk.ThunkInterface {
36-
return (dispatch, getState): void => {
37-
const {progress} = getState();
38-
dispatch({ type: PAGE_POSITION_LOAD, payload: { progress } });
39-
};
40-
}
41-
4235
export function pagePositionSet(pagePosition: CR.PagePosition): Action {
4336
return { type: PAGE_POSITION_SET, payload: { pagePosition } };
4437
}

src/actions/progress.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import {
2-
PROGRESS_LOAD, COMPLETE_PAGE, COMPLETE_TUTORIAL
2+
PROGRESS_PAGE_POSITION_LOAD, PROGRESS_LOAD, COMPLETE_PAGE, COMPLETE_TUTORIAL
33
} from './_types';
4-
import {pagePositionLoad} from './page';
4+
5+
export function progressPagePositionLoad(): ReduxThunk.ThunkInterface {
6+
return (dispatch, getState): void => {
7+
const {progress} = getState();
8+
dispatch({ type: PROGRESS_PAGE_POSITION_LOAD, payload: { progress } });
9+
};
10+
}
511

612
export function progressLoad(): ReduxThunk.ThunkInterface {
713
return (dispatch, getState): void => {
814
const {tutorial} = getState();
915
dispatch({ type: PROGRESS_LOAD, payload: { tutorial } });
1016
// call pagePositionLoad after progress loads
11-
dispatch(pagePositionLoad());
17+
dispatch(progressPagePositionLoad());
1218
};
1319
}
1420

src/actions/setup.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import {SETUP_VERIFY} from './_types';
2-
import {packageSet} from './package';
1+
import {SETUP_VERIFY, SETUP_PACKAGE} from './_types';
32

43
export function setupVerify(): ReduxThunk.ThunkInterface {
54
return (dispatch, getState): void => {
6-
dispatch(packageSet());
5+
dispatch(setupPackage());
76
const {dir, packageJson} = getState();
87
dispatch({ type: SETUP_VERIFY, payload: { dir, packageJson } });
98
};
109
}
10+
11+
export function setupPackage(): ReduxThunk.ThunkInterface {
12+
return (dispatch, getState): void => {
13+
const {dir} = getState();
14+
dispatch({ type: SETUP_PACKAGE, payload: { dir } });
15+
};
16+
}

src/reducers/package-json/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {PACKAGE_SET} from '../../actions/_types';
1+
import {SETUP_PACKAGE} from '../../actions/_types';
22
import {join} from 'path';
33
import {readFileSync} from 'fs';
44
import {fileExists} from '../../services/exists';
@@ -8,7 +8,7 @@ export default function packageJsonReducer(
88
): PackageJson {
99
switch (action.type) {
1010

11-
case PACKAGE_SET:
11+
case SETUP_PACKAGE:
1212
const {dir} = action.payload;
1313
const pathToPackageJson = join(dir, 'package.json');
1414
if (fileExists(pathToPackageJson)) {

src/reducers/page-position/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {
2-
PAGE_SET, PAGE_POSITION_SET, PAGE_POSITION_LOAD
2+
PAGE_SET, PAGE_POSITION_SET, PROGRESS_PAGE_POSITION_LOAD
33
} from '../../actions/_types';
44

55
export default function pagePositionReducer(
66
pagePosition = 0, action: Action
77
): CR.PagePosition {
88
switch (action.type) {
99

10-
case PAGE_POSITION_LOAD:
10+
case PROGRESS_PAGE_POSITION_LOAD:
1111
const pages = action.payload.progress.pages;
1212
const firstFail = pages.indexOf(false);
1313
return firstFail < 0 ? pages.length - 1 : firstFail;

tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"src/actions/config-task-tests.ts",
5757
"src/actions/hint.ts",
5858
"src/actions/index.ts",
59-
"src/actions/package.ts",
6059
"src/actions/page.ts",
6160
"src/actions/progress.ts",
6261
"src/actions/route.ts",

0 commit comments

Comments
 (0)