Skip to content

Commit

Permalink
types(vest): Add a dedicated VestTests plural type
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Jun 10, 2022
1 parent 59940e1 commit b062abb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
10 changes: 6 additions & 4 deletions packages/vest/src/core/state/createStateRef.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NestedArray } from 'nestedArray';
import { NestedArray } from 'nestedArray';
import type { State, UseState } from 'vast';

import VestTest from 'VestTest';
Expand All @@ -19,7 +19,7 @@ export default function createStateRef(
testObjects: state.registerStateKey<TestObjects>(prev => {
return {
prev: prev ? prev.current : [],
current: [] as NestedArray<VestTest>,
current: [] as VestTests,
};
}),
};
Expand Down Expand Up @@ -52,6 +52,8 @@ type TestCallbacks = {
};

type TestObjects = {
prev: NestedArray<VestTest>;
current: NestedArray<VestTest>;
prev: VestTests;
current: VestTests;
};

export type VestTests = NestedArray<VestTest>;
7 changes: 2 additions & 5 deletions packages/vest/src/core/state/stateHooks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import asArray from 'asArray';
import assign from 'assign';
import createCache from 'cache';
import type { NestedArray } from 'nestedArray';
import * as nestedArray from 'nestedArray';
import optionalFunctionValue from 'optionalFunctionValue';
import { ValueOf } from 'utilityTypes';

import VestTest from 'VestTest';
import type { StateKey, StateRef, StateValue } from 'createStateRef';
import type { StateKey, StateRef, StateValue, VestTests } from 'createStateRef';
import ctx from 'ctx';

// STATE REF
Expand Down Expand Up @@ -78,9 +77,7 @@ export function useRefreshTestObjects(): void {
useSetTests(tests => tests);
}

export function useSetTests(
handler: (current: NestedArray<VestTest>) => NestedArray<VestTest>
): void {
export function useSetTests(handler: (current: VestTests) => VestTests): void {
const [, testObjects] = useTestObjects();

testObjects(({ current, prev }) => ({
Expand Down
7 changes: 3 additions & 4 deletions packages/vest/src/core/test/lib/useTestAtCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import defaultTo from 'defaultTo';
import { isEmpty, isNotEmpty } from 'isEmpty';
import { isNullish } from 'isNullish';
import * as nestedArray from 'nestedArray';
import type { NestedArray } from 'nestedArray';
import { deferThrow } from 'throwError';

import VestTest from 'VestTest';
import { VestTests } from 'createStateRef';
import isSameProfileTest from 'isSameProfileTest';
import { shouldAllowReorder, useCurrentPath, useCursor } from 'isolate';
import { usePrevTestByKey, useRetainTestKey } from 'key';
Expand All @@ -32,8 +32,7 @@ export function useTestAtCursor(newTestObject: VestTest): VestTest {
return newTestObject;
}

let prevTest: NestedArray<VestTest> | VestTest | null =
useGetTestAtCursor(prevTests);
let prevTest: VestTests | VestTest | null = useGetTestAtCursor(prevTests);

if (!isNullish(newTestObject.key)) {
const nextTest = handleKeyTest(newTestObject.key, newTestObject);
Expand Down Expand Up @@ -75,7 +74,7 @@ export function useSetTestAtCursor(testObject: VestTest): void {
);
}

function useGetTestAtCursor(tests: NestedArray<VestTest>): VestTest {
function useGetTestAtCursor(tests: VestTests): VestTest {
const cursorPath = useCurrentPath();

return nestedArray.valueAtPath(tests, cursorPath) as VestTest;
Expand Down

1 comment on commit b062abb

@vercel
Copy link

@vercel vercel bot commented on b062abb Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vest-next – ./website

vest-next-git-latest-ealush.vercel.app
vest-website.vercel.app
vest-next.vercel.app
vest-next-ealush.vercel.app

Please sign in to comment.