Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor(vest): Add subscribe to specific events #1154

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

ealush
Copy link
Owner

@ealush ealush commented Sep 3, 2024

Allowing usage of suite.subscribe with a more granular event, such as:

export type Events =
  | 'TEST_RUN_STARTED'
  | 'TEST_COMPLETED'
  | 'ALL_RUNNING_TESTS_FINISHED'
  | 'REMOVE_FIELD'
  | 'RESET_FIELD'
  | 'RESET_SUITE'
  | 'SUITE_RUN_STARTED'
  | 'SUITE_CALLBACK_RUN_FINISHED'
  | 'DONE_TEST_OMISSION_PASS';

This means that subscribe won't fire like crazy whenever being used.

This is the essence of the change, the rest is just to make it easier to use the events as strings:

  function subscribe(event: Events, cb: CB): CB<void>;
  function subscribe(cb: CB): CB<void>;
  function subscribe(...args: [event: Events, cb: CB] | [cb: CB]): CB<void> {
    const [cb, event] = args.reverse() as [CB, Events];
    return VestBus.on(event ?? '*', () => {
      cb();
    }).off;
  }

Copy link

vercel bot commented Sep 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 4, 2024 5:52pm
vest-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 4, 2024 5:52pm

@ealush ealush force-pushed the 2024-09-03-subscribe-to-specific-events branch from d462791 to cbd49a4 Compare September 4, 2024 17:47
@ealush ealush marked this pull request as ready for review September 4, 2024 17:52
@ealush ealush merged commit 3b91d44 into latest Sep 4, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant