Skip to content

Conversation

@haradakunihiko
Copy link
Owner

@haradakunihiko haradakunihiko commented Sep 4, 2025

Summary

Add external cancellation (abort) support for confirmation dialogs.

  • Supports AbortController-based cancellation (recommended)
  • Adds utility functions abort(promise) and abortAll()
  • When aborted, the Promise rejects with AbortError and the UI unmounts automatically
  • createConfirmation now accepts an optional second argument { signal?: AbortSignal }

Changes

  • New: src/controls.ts
    • Lightweight registry to track pending confirmations and cancel them
    • Exposes abort(promise), abortAll(), and attachAbortSignal
  • Update: src/createConfirmation.ts
    • Registers created Promises and ensures reject + unmount on cancellation
    • Accepts control?: { signal?: AbortSignal } and wires the signal
  • Types: src/types.ts
    • Reflects control?: { signal?: AbortSignal } in ConfirmationContext#createConfirmation
  • Exports: src/index.ts
    • Exposes abort and abortAll
  • Docs: README.md
    • Adds a "Cancellation (Abort)" section
  • Tests: __tests__/abort.test.js
    • Covers single abort, abortAll for multiple, and AbortSignal-driven cancellation

Usage

  • Using AbortController (recommended)
const confirm = createConfirmation(confirmable(MyDialog));
const ac = new AbortController();
const p = confirm({ message: 'Delete?' }, { signal: ac.signal });
// Later
ac.abort(); // p rejects with AbortError and the dialog closes
  • Using utility functions
const confirm = createConfirmation(confirmable(MyDialog));
const p = confirm({ message: 'Delete?' });
abort(p);     // cancel one
abortAll();   // cancel all pending

Compatibility

  • Existing calls createConfirmation(props) continue to work; the second parameter is optional.
  • Aborted promises reject with an error whose name === 'AbortError'. If your app relies on specific error types, please handle accordingly.

Tests

  • Adds JSDOM-based unit tests. Verified locally with npm test.

If you want additional docs (screenshots, migration notes, etc.), I can add them.

@haradakunihiko haradakunihiko changed the base branch from feature/to-typescript to master September 4, 2025 04:15
@haradakunihiko haradakunihiko changed the base branch from master to typescript September 4, 2025 04:16
@haradakunihiko haradakunihiko changed the base branch from typescript to feature/to-typescript September 4, 2025 04:16
@haradakunihiko haradakunihiko changed the base branch from feature/to-typescript to master September 17, 2025 23:54
@haradakunihiko haradakunihiko changed the base branch from master to feature/to-typescript September 17, 2025 23:54
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