Skip to content

Commit

Permalink
fix(typings): meet new typescript requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Apr 7, 2020
1 parent 3a0ca40 commit 9e59433
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/interactive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from 'chalk';
import * as chalk from 'chalk';
import { prompt } from 'inquirer';
import { resolve } from 'path';
import { WriteStream } from 'tty';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/try-panic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from 'chalk';
import * as chalk from 'chalk';

export const tryPanic = (fn: (...args: any[]) => any, message: string) => {
try {
Expand Down
21 changes: 11 additions & 10 deletions src/machine/tree/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import { isBranch, isNode } from './nodes';

export type TreeActions = MachineOptions<TreeContext, TreeEvent>['actions'];

const isSelectChildEvent = (event: TreeEvent): event is SelectChildEvent =>
event.type === 'SELECT_CHILD';

export const actions: TreeActions = {
incrementRetries: assign((context) => ({ retries: context.retries + 1 })),
resetRetries: assign(() => ({ retries: 0 })),
selectChild: assign<TreeContext, SelectChildEvent | EventObject>(
({ currentNode }, { childIndex: i }) => ({
currentNode:
isBranch(currentNode) && isNode(currentNode.children[i])
? currentNode.children[i]
: currentNode,
}),
),
selectChild: assign(({ currentNode }, event) => ({
currentNode:
isSelectChildEvent(event) &&
isBranch(currentNode) &&
isNode(currentNode.children[event.childIndex])
? currentNode.children[event.childIndex]
: currentNode,
})),
selectRoot: assign((context) => ({ currentNode: context.rootNode })),
};
4 changes: 0 additions & 4 deletions src/machine/tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface TreeSchema {
export interface TreeContext<NodeType = Node> {
currentNode: NodeType;
error: Error | null;
retries: number;
rootNode: Node;
}

Expand Down Expand Up @@ -71,7 +70,6 @@ export const createTreeMachine = (rootNode: Node, id: string = 'tree-machine'):
context: {
currentNode: rootNode,
error: null,
retries: 0,
rootNode,
},
id,
Expand Down Expand Up @@ -106,15 +104,13 @@ export const createTreeMachine = (rootNode: Node, id: string = 'tree-machine'):
success: {
on: {
'': {
actions: ['resetRetries'],
target: VISIT_NODE,
},
},
},
failure: {
on: {
RETRY: {
actions: ['incrementRetries'],
target: 'loading',
},
},
Expand Down

0 comments on commit 9e59433

Please sign in to comment.