diff --git a/src/interactive.ts b/src/interactive.ts index 4835d4d..bafe6c0 100644 --- a/src/interactive.ts +++ b/src/interactive.ts @@ -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'; diff --git a/src/lib/try-panic.ts b/src/lib/try-panic.ts index 13390fe..977aa5e 100644 --- a/src/lib/try-panic.ts +++ b/src/lib/try-panic.ts @@ -1,4 +1,4 @@ -import chalk from 'chalk'; +import * as chalk from 'chalk'; export const tryPanic = (fn: (...args: any[]) => any, message: string) => { try { diff --git a/src/machine/tree/actions.ts b/src/machine/tree/actions.ts index afdf2cb..3b46cc1 100644 --- a/src/machine/tree/actions.ts +++ b/src/machine/tree/actions.ts @@ -4,16 +4,17 @@ import { isBranch, isNode } from './nodes'; export type TreeActions = MachineOptions['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( - ({ 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 })), }; diff --git a/src/machine/tree/index.ts b/src/machine/tree/index.ts index 05abbed..8bbe0f5 100644 --- a/src/machine/tree/index.ts +++ b/src/machine/tree/index.ts @@ -23,7 +23,6 @@ export interface TreeSchema { export interface TreeContext { currentNode: NodeType; error: Error | null; - retries: number; rootNode: Node; } @@ -71,7 +70,6 @@ export const createTreeMachine = (rootNode: Node, id: string = 'tree-machine'): context: { currentNode: rootNode, error: null, - retries: 0, rootNode, }, id, @@ -106,7 +104,6 @@ export const createTreeMachine = (rootNode: Node, id: string = 'tree-machine'): success: { on: { '': { - actions: ['resetRetries'], target: VISIT_NODE, }, }, @@ -114,7 +111,6 @@ export const createTreeMachine = (rootNode: Node, id: string = 'tree-machine'): failure: { on: { RETRY: { - actions: ['incrementRetries'], target: 'loading', }, },