Skip to content

Improve Cancellation Flow, Refactor CancelBag, ScreenActionStore and Error Handling.#21

Open
ThangKM wants to merge 9 commits intoanthony1810:mainfrom
ThangKM:cancellation_flow
Open

Improve Cancellation Flow, Refactor CancelBag, ScreenActionStore and Error Handling.#21
ThangKM wants to merge 9 commits intoanthony1810:mainfrom
ThangKM:cancellation_flow

Conversation

@ThangKM
Copy link
Collaborator

@ThangKM ThangKM commented Mar 15, 2026

Refactor CancelBag, ScreenActionStore, and Error Handling

Summary

Refactors the core action dispatching and error handling pipeline. ScreenActionStore now centralizes loading state tracking and error presentation in a single dispatch method, removing boilerplate from individual store implementations. A new NonPresentableError protocol allows errors to be silently logged instead of shown to the user.

Changes

CancelBag

  • Renamed CancellerAnyTask (now public) — callers can await task completion via waitComplete()
  • Renamed CancelStrategyDuplicatePolicy, init parameter duplicate:onDuplicate:
  • Task.store(in:) now returns @discardableResult AnyTask
  • Uses Task.immediate on iOS 26+ for eager scheduling

DisplayableError & Error Handling

  • Added NonPresentableError protocol — errors conforming with isSilent == true are logged but not shown to the user
  • DisplayableError now wraps originalError and exposes isSilent
  • Added convenience init(error:) initializer

ScreenActionStore

  • receive(action:) is now async throws — stores simply throw errors instead of manually calling showError
  • Added viewState associated type requirement for direct state access
  • Centralized loading start/finish and error routing in a new dispatch(action:) method
  • nonisolatedReceive now returns @discardableResult AnyTask

AsyncAction

  • Added #isolation parameter for caller-isolated execution
  • Added optional name property
  • Uses Task.immediate on iOS 26+

Tests

  • Updated TestStore and TestLoadMoreStore to the new async throws API
  • Added test for non-duplicate action locking (different params → both execute)
  • Added test for silent error handling (NonPresentableError)
  • Removed unused ScreenStatetKitTests.swift

Bug Fix

  • Fixed typo: ternimateLoadmoreViewterminateLoadMoreView

ThangKM added 9 commits March 8, 2026 12:09
…plify ScreenActionStore

- CancelBag: auto-remove completed tasks via watch(), add isEmpty/count,
  accept AnyHashable identifiers, make bag parameter optional
- StreamProducer: extract StreamStorage class with deinit cleanup,
  deprecate nonIsolatedFinish()
- ScreenActionStore: replace binding(state:) with receive(action:),
  add nonisolatedReceive helper with CancelBag support
- Add CancelBagTests for auto-removal of completed tasks
- Rename Canceller to AnyTask (now public) with discardable store results
- Rename CancelStrategy to DuplicatePolicy, init param to onDuplicate
- Add NonPresentableError protocol for silent error handling
- Enrich DisplayableError with originalError, isSilent, and Error init
- Centralize loading/error flow in ScreenActionStore.dispatch
- Make ScreenActionStore.receive async throws, add viewState requirement
- Update AsyncAction with Task.immediate for iOS 26 and #isolation
- Fix typo: ternimateLoadmoreView -> terminateLoadMoreView
- Add tests for non-duplicate action locking and silent errors
- Remove unused ScreenStatetKitTests.swift
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.

1 participant