Skip to content

Commit

Permalink
patch(vest): removed state subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 10, 2021
1 parent 80f690f commit d96f428
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 64 deletions.

This file was deleted.

25 changes: 0 additions & 25 deletions packages/vest/src/core/suite/__tests__/subscribe.test.ts

This file was deleted.

26 changes: 2 additions & 24 deletions packages/vest/src/core/suite/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import isFunction from 'isFunction';
import throwError from 'throwError';
import { createState } from 'vast';

import createStateRef, { TStateRef } from 'createStateRef';
import createStateRef from 'createStateRef';
import context from 'ctx';
import matchingFieldName from 'matchingFieldName';
import { IVestResult, produceFullResult } from 'produce';
Expand All @@ -21,23 +21,14 @@ export default function create<T extends (...args: any[]) => void>(
get: () => TDraftResult;
reset: () => void;
remove: (fieldName: string) => void;
subscribe: (handler: () => void) => void;
} {
if (!isFunction(suiteCallback)) {
throwError(
'Suite initialization error. Expected `tests` to be a function.'
);
}

const handlers: ((...args: unknown[]) => void)[] = [];
const state = createState(() => {
handlers.forEach(fn =>
fn({
suiteState: stateRef,
type: 'suiteStateUpdate',
})
);
});
const state = createState();

const stateRef = createStateRef(state, { suiteId: genId() });

Expand All @@ -47,7 +38,6 @@ export default function create<T extends (...args: any[]) => void>(
get: () => TDraftResult;
reset: () => void;
remove: (fieldName: string) => void;
subscribe: (handler: () => void) => void;
}

const suite: IVestSuite = assign(
Expand Down Expand Up @@ -78,18 +68,6 @@ export default function create<T extends (...args: any[]) => void>(
});
}),
reset: state.reset,
subscribe(
handler: (stateEvent: { type: string; suiteState: TStateRef }) => void
) {
if (!isFunction(handler)) return;

handlers.push(handler);

handler({
type: 'suiteSubscribeInit',
suiteState: stateRef,
});
},
}
);

Expand Down

0 comments on commit d96f428

Please sign in to comment.