-
Notifications
You must be signed in to change notification settings - Fork 49
feat: add abort/cancel support for confirmations #131
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
確認ダイアログを外部から中止できる機能を追加しました。 ## 主な変更 ### 新機能 - AbortController/AbortSignalによるキャンセルをサポート - abort()関数で個別のPromiseをキャンセル - abortAll()関数で全ての未解決Promiseをキャンセル - カスタムAbortErrorクラスを追加 ### API変更 - createConfirmation()が第2引数でoptionsを受け取るように拡張 - options.signalでAbortSignalを指定可能 - 後方互換性を完全に維持 ### 実装詳細 - src/controls.ts: abort機能の実装 - src/types.ts: ConfirmationOptions型を追加 - src/createConfirmation.ts: Promiseレジストリへの登録とAbortSignal対応 - src/index.ts: abort/abortAllをexport ### テスト - __tests__/abort.test.ts: 7つのテストケースを追加 - 全76個のテストが成功 ### ドキュメント - READMEに使用例とエラーハンドリングの説明を追加 ## PR #127からの改善点 1. パラメータ名をcontrolからoptionsに変更(より一般的な命名) 2. カスタムAbortErrorクラスを定義(型安全性の向上) 3. より充実したテストカバレッジ 4. エラーハンドリングの例をREADMEに追加 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Update all code comments from Japanese to English for better international collaboration. Changes: - src/controls.ts: Translate comments to English - src/createConfirmation.ts: Translate comments to English - __tests__/abort.test.ts: Translate comments to English 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Change documentation order to show utility functions first as the simpler approach, and AbortController as an advanced option for fine-grained control. Changes: - README.md: Move utility functions section before AbortController - README.md: Label AbortController section as "Advanced" - README.md: Remove "Recommended" label from AbortController 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Change from reject-based abort to resolve-based close pattern, following react-call's design philosophy where external completion is treated as a normal resolution rather than an error.
## Breaking Changes
- Renamed `abort()` → `close()` and `abortAll()` → `closeAll()`
- External completion now **resolves** with response value instead of rejecting
- `AbortError` class removed (no longer needed)
- `ConfirmationOptions` now requires `abortResponse` parameter for AbortSignal
## Changes
### API Changes
- `close(promise, response)` - Closes promise with response value
- `closeAll(response)` - Closes all pending promises with response value
- AbortSignal requires `{ signal, abortResponse }` to specify response value
### Type Safety
- Generic type `<R>` preserved through close operations
- TypeScript ensures response type matches Promise type
### Benefits
- No try-catch needed for external completion
- External completion treated as normal flow, not error
- Simpler API aligned with react-call design
## Migration
Before:
```typescript
abort(promise) // → rejects with AbortError
try {
await promise
} catch (e) {
if (e.name === 'AbortError') // handle
}
```
After:
```typescript
close(promise, false) // → resolves with false
const result = await promise // false
if (!result) // handle
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
abortResponseが指定されていない場合、Promiseはabort reasonでrejectされるようになりました。 Changes: - ConfirmationHandleにrejectを追加 - attachAbortSignalをabortResponseオプショナル対応 - 指定あり: Promiseをその値でresolve - 指定なし: Promiseをabort reasonでreject - テストを追加(abortResponse省略時の動作確認) - READMEを更新(close/closeAllを推奨、AbortControllerは代替手段) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Replace close() with proceed() for resolving confirmations - Add dismiss() to close UI without resolving/rejecting Promise - Add cancel() for rejecting confirmations - Remove closeAll() and AbortController support - Rename abort.test.ts to controls.test.ts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for externally cancelling confirmation dialogs.
abort(promise)to cancel individual promisesabortAll()to cancel all pending promisesKey Changes
New Files
src/controls.ts: Abort functionality implementationAbortErrorclassabort(),abortAll(),attachAbortSignal()functions__tests__/abort.test.ts: 7 test casesModified Files
src/types.ts: AddedConfirmationOptionstypesrc/createConfirmation.ts: Promise registry registration and AbortSignal supportsrc/index.ts: Exportabort/abortAllREADME.md: Added usage examples and error handling documentationUsage
Via AbortController (Recommended)
Via Utility Functions
Testing
Run tests:
npm test npm run typecheck npm run buildCompatibility
createConfirmationis optionalAbortError(name === 'AbortError')Improvements over PR #127
controltooptions(more conventional)AbortErrorclass for better type safety🤖 Generated with Claude Code