Skip to main content
cngx-src documentation

CreateCommitHandler

Interface

projects/forms/select/shared/create-commit-handler.ts

Import#

import { CreateCommitHandler } from '@cngx/forms/select'

Description#

API returned from createCreateCommitHandler. T is a phantom marker so consumers type the handler as CreateCommitHandler<Tag, readonly Tag[]> instead of CreateCommitHandler<unknown, readonly Tag[]> - constrains the factory call-site even though only Prev appears in the public shape.

Index#

Methods#

dispatch#void
dispatch(draft: literal type, searchTerm: string, previousSnapshot: Prev)

Run a quick-create through the commit flow. Pessimistic: panel stays open, controller flips to pending (drives isPending inside the slot context). On success: patch localItemsBuffer, fire onCreated (consumer writes the value slot), announce, close conditionally. On error: commit-error surface fires; value slot is untouched.

Accepted deviation from plan (master ยง3 Commit 5): the plan described an "optimistic add to localItems before commit" path. True optimistic UX requires a tempValueFactory(draft) since T is opaque to the handler; pessimistic + isPending delivers the same perceived immediacy for now.

                     `T | undefined`; multi: `readonly T[]`)
                     forwarded to `onCreated` unchanged.
@paramdraftliteral type

Drafted item carrying at least a label.

@paramsearchTermstring

Live search term at dispatch time.

@parampreviousSnapshotPrev

Consumer-captured snapshot (single: T | undefined; multi: readonly T[]) forwarded to onCreated unchanged.

retryLast#void

Re-dispatch the most recent dispatch call with the cached draft, search term, and previous-value snapshot. Routes through begin(...) so supersede semantics apply - a stale retry after a fresh commit is superseded cleanly. No-op when never dispatched.

Exposed as the retry callback on CngxSelectActionCallbacks; consumer templates wire it to a "Try again" button without re-sourcing the draft.