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

Add suite.subscribe method #1080

Merged
merged 2 commits into from
Sep 25, 2023
Merged

Add suite.subscribe method #1080

merged 2 commits into from
Sep 25, 2023

Conversation

ealush
Copy link
Owner

@ealush ealush commented Sep 25, 2023

Q A
New feature?
Documentation?
Tests added?
Related issues #1073

Subscribing to Suite State Changes

You can subscribe to changes in the suite state by calling suite.subscribe(callback). The callback will be called whenever the suite state changes internally.

suite.subscribe(() => {
  const result = suite.get();
  // ... Do something with the result
});

Unsubscribing from Suite State Changes

The subscribe method returns a function that you can call to unsubscribe from the suite state changes:

const unsubscribe = suite.subscribe();

@vercel
Copy link

vercel bot commented Sep 25, 2023

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 25, 2023 10:16pm
vest-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 25, 2023 10:16pm

@ealush ealush assigned ealush and unassigned ealush Sep 25, 2023
@ealush
Copy link
Owner Author

ealush commented Sep 25, 2023

@vonagam Please take a look at this, I believe this answers what we discussed

@vonagam
Copy link
Contributor

vonagam commented Sep 25, 2023

Looks right.

But need a way to unsubscribe:

function subscribe(cb: CB) {
  const {off} = VestBus.on('*', () => {
    cb();
  });
  
  return off;
}

Also, interesting that every Vest.test call triggers event bus, I thought that there was some optimizations to call only once for those sync tests. Not a problem, just a note for myself to add debounce for a subscribe callback provided.

@ealush ealush force-pushed the 2023-09-22-subscribe branch from 36272f0 to d2cc265 Compare September 25, 2023 22:11
@ealush
Copy link
Owner Author

ealush commented Sep 25, 2023

@vonagam added the unsubscribe function as the function's return.

And yeah. basically, internal communication in vest is done using events. This prevents different parts of the framework from knowing of one another, so they just report their current state and Vest reacts to these changes. Same with test results.

@ealush ealush merged commit 828085b into latest Sep 25, 2023
4 of 5 checks passed
@ealush ealush deleted the 2023-09-22-subscribe branch October 25, 2023 16:42
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.

2 participants