npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

svelte-lock

v1.2.0

Published

Reactive lock manager for Svelte 5

Downloads

52

Readme

svelte-lock

version downloads

Reactive lock manager for Svelte 5

Installation

npm install svelte-lock

Usage

A lock key can be a string or a symbol. You can use one or multiple keys to manage independent or shared lock conditions.

1. Initialize lock context

Call initLockContext() once at the root of your Svelte app:

<script>
	import { initLockContext } from 'svelte-lock';

	initLockContext();
</script>

2. Use useLock() inside a component

Use useLock() to observe and control the lock state for one or more keys.

Single key

<script>
	import { useLock } from 'svelte-lock';

	const task = useLock(Symbol());

	function run() {
		task.lock();

		setTimeout(() => {
			task.release();
		}, 1000);
	}
</script>

<button on:click={run} disabled={task.isLocked}>
	{#if task.isLocked}
		Running...
	{:else}
		Run
	{/if}
</button>

Multiple keys

<script>
	const lock = useLock(['saving', 'submitting']);

	if (lock.isLocked) {
		// true if either key is locked
	}
</script>

3. Use getLocker() for lower-level control

<script>
	import { getLocker } from 'svelte-lock';

	const locker = getLocker();
	const release = locker.lock(['form', 'submit']);

	// Later
	release();
</script>

API

initLockContext(): void

Initializes the internal lock state. Must be called once in a root-level component.


useLock(keys?: LockKey | LockKey[]): { ... }

Returns an object for observing and controlling a specific lock or group of locks. If no key is provided, a unique symbol will be used automatically.

  • keys: LockKey[] — the list of keys used for this lock
  • isLocked: boolean — reactive value; true if any of the provided keys are currently locked.
  • lock(): void — locks all provided keys. Already locked keys stay locked.
  • release(): void — removes the lock for all provided keys.

getLocker(): { ... }

Returns an object for low-level lock operations with the following methods:

  • lock(keys: LockKey[]): () => void
    Locks the given keys. Returns a function that releases them.

  • release(keys: LockKey[]): void
    Manually removes keys from the lock.

  • observe(keys: LockKey[]): { isLocked: boolean }
    Creates a reactive observer for the given keys.
    The isLocked property is true if any of the specified keys are currently locked.

  • isLocked(keys: LockKey[]): boolean
    Returns true if any of the given keys are currently locked.
    This is a non-reactive snapshot and does not update automatically.


License

MIT