Skip to content

feat: add useWebLocks (Web Locks API) and useLeaderElection #4574

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

d--j
Copy link

@d--j d--j commented Feb 9, 2025

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).

Description

Introduces a reactive version of the Web Locks API that automatically releases the locks when the current scope gets disposed.

Use this new composable for another new composable useLeaderElection with which one can elect one of possible many tabs to do work. This can be used to e.g. refresh a session only in one tab.

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request new function labels Feb 9, 2025
@d--j d--j changed the title feat: add useOnceInAllTabs (Web Locks API) feat: add useWebLocks (Web Locks API) and useLeaderElection Feb 10, 2025
@d--j d--j force-pushed the useOnceInAllTabs branch 3 times, most recently from a957f0e to 7b6789d Compare February 10, 2025 21:57
Copy link
Collaborator

@OrbisK OrbisK left a comment

Choose a reason for hiding this comment

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

i like it.

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Feb 11, 2025
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Feb 13, 2025
@d--j d--j marked this pull request as draft February 13, 2025 11:38
@d--j
Copy link
Author

d--j commented Feb 13, 2025

I just pushed a new version but also converted this PR to a draft since I am not finished polishing it (useWebLocks) and coding the demo (useLeaderElection). Unfortunately, my day job demands some attention and I need to step away for a bit.

Thank you, @OrbisK, for very valuable pointers and code reviews so far!

```ts
import { useLeaderElection } from '@vueuse/core'

const { asLeader, isElected, isSupported } = useLeaderElection({ name: 'lock-name' })
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const { asLeader, isElected, isSupported } = useLeaderElection({ name: 'lock-name' })
const { asLeader, isLeader, isSupported } = useLeaderElection({ name: 'lock-name' })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new function size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants