Skip to content

Commit 5a51f42

Browse files
committed
lodash refactor and typings
1 parent 5327262 commit 5a51f42

File tree

11 files changed

+19278
-29
lines changed

11 files changed

+19278
-29
lines changed

lib/actions/alert.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
"use strict";
22
var store_1 = require('../store/store');
33
var actionTypes_1 = require('./actionTypes');
4-
var _ = require('lodash');
54
function toggleAlert(alert) {
65
var isOpen = store_1.store.getState().alert.open;
76
if (!alert) {
87
alert = { message: '', action: '', open: false };
98
}
109
else {
11-
alert = _.assign(alert, { open: !isOpen });
10+
alert = Object.assign({}, { open: !isOpen }, alert);
1211
}
1312
return { type: actionTypes_1.TOGGLE_ALERT, payload: { alert: alert } };
1413
}

lib/actions/page-actions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
var actionTypes_1 = require('./actionTypes');
33
var store_1 = require('../store/store');
44
var package_1 = require('../services/package');
5-
var flatten = require('lodash').flatten;
5+
var lodash_1 = require('lodash');
66
function setPage(selectedPosition) {
77
if (selectedPosition === void 0) { selectedPosition = { chapter: 0, page: 0 }; }
88
if (selectedPosition.completed) {
99
return { type: actionTypes_1.SET_ROUTE, payload: { route: 'final' } };
1010
}
1111
var page = package_1.default.getPage(selectedPosition);
1212
var tasks = package_1.default.getTasks(selectedPosition);
13-
var taskTests = flatten(tasks.map(function (task) { return task.tests || []; }));
13+
var taskTests = lodash_1.flatten(tasks.map(function (task) { return task.tests || []; }));
1414
var actions = tasks.map(function (task) { return task.actions || []; });
1515
return { type: actionTypes_1.SET_PAGE, payload: { page: page, tasks: tasks, position: selectedPosition, taskTests: taskTests, actions: actions } };
1616
}

lib/reducers/editor-actions/editor-actions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
var actionTypes_1 = require('../../actions/actionTypes');
3-
var times = require('lodash').times;
3+
var lodash_1 = require('lodash');
44
var actions_1 = require('./actions');
55
function handleEditorActions(actionArray) {
66
if (actionArray && actionArray.length) {
@@ -21,7 +21,7 @@ function editorActionsReducer(editorActions, action) {
2121
actions = action.payload.actions;
2222
var nextTaskPosition = action.payload.result.taskPosition;
2323
if (nextTaskPosition > currentTaskPosition) {
24-
times(handleEditorActions(actions.shift()), nextTaskPosition - currentTaskPosition);
24+
lodash_1.times(handleEditorActions(actions.shift()), nextTaskPosition - currentTaskPosition);
2525
currentTaskPosition = nextTaskPosition;
2626
}
2727
return actions;

lib/services/package.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var path_1 = require('path');
33
var actions_1 = require('../actions/actions');
44
var store_1 = require('../store/store');
5-
var _a = require('lodash'), cloneDeep = _a.cloneDeep, isString = _a.isString;
5+
var lodash_1 = require('lodash');
66
function configTestString(config, packageName, test) {
77
if (window.coderoad.win) {
88
test = test.split('/').join('\\');
@@ -36,7 +36,7 @@ var PackageService = (function () {
3636
};
3737
PackageService.prototype.page = function (_a) {
3838
var chapter = _a.chapter, page = _a.page;
39-
return cloneDeep(this.data.chapters[chapter].pages[page]);
39+
return lodash_1.cloneDeep(this.data.chapters[chapter].pages[page]);
4040
};
4141
PackageService.prototype.getPackage = function () {
4242
return this.packageJson;
@@ -47,7 +47,7 @@ var PackageService = (function () {
4747
return !tasks ? [] : tasks.map(function (task) {
4848
if (task.tests) {
4949
task.tests = task.tests.map(function (test) {
50-
if (isString(test)) {
50+
if (lodash_1.isString(test)) {
5151
return configTestString(config, _this.packageName, test);
5252
}
5353
else {

src/actions/alert.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import {store} from '../store/store';
22
import {TOGGLE_ALERT, REPLAY_ALERT} from './actionTypes';
3-
const _ = require('lodash');
43

54
export function toggleAlert(alert?: CR.Alert): CR.Action {
65
const isOpen = store.getState().alert.open;
76
if (!alert) {
87
alert = { message: '', action: '', open: false };
98
} else {
10-
alert = _.assign(alert, { open: !isOpen });
9+
alert = Object.assign({}, { open: !isOpen }, alert);
1110
}
1211
return { type: TOGGLE_ALERT, payload: { alert } };
1312
}

src/actions/page-actions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {SET_ROUTE, SET_PAGE} from './actionTypes';
22
import {store} from '../store/store';
33
import Package from '../services/package';
4-
const {flatten} = require('lodash');
4+
import {flatten} from 'lodash';
55

66
export function setPage(selectedPosition: CR.Position = { chapter: 0, page: 0 }): CR.Action {
77
if (selectedPosition.completed) {

src/reducers/editor-actions/editor-actions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {SET_PAGE, TEST_RESULT} from '../../actions/actionTypes';
2-
const {times} = require('lodash');
2+
import {times} from 'lodash';
33
import {editorActions} from './actions';
44

55
function handleEditorActions(actionArray: string[]): void {

src/services/package.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {join} from 'path';
22
import {setGlobals, projectComplete} from '../actions/actions';
33
import {store} from '../store/store';
4-
const {cloneDeep, isString} = require('lodash');
4+
import {cloneDeep, isString} from 'lodash';
55

66
function configTestString(config: CR.Config,
77
packageName: string, test: string): string {

0 commit comments

Comments
 (0)