-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
@async-library/core will contain all the core functionality that Async Library provides. It will generally not be used directly, but be a dependency of @async-library/react-async-hook for example. It should have feature parity with react-async and react-async-hook (outside of React specifics).
This description is updated as the discussion unfolds.
Features
- Standardized API (both in and out)
- Full state management for a single instance in local state
- No global store (otherwise you might as well use Redux Saga)
- Cancellation (with AbortController)
- DevTools integration (e.g. allow replaying a promiseFn)
To discuss:
- Should we use generators instead of promises?
- Should we use an internal state machine?
- Should we allow users to create their own async state machine?
Core API
States:
initialnothing happened yet (orreinitializewas invoked)pendingpromise is loading or pausedfulfilledpromise was fulfilled with datarejectedpromise was rejected with error
Config options:
fnasync function that will be invoked onrunrunOnInitflag to enable running on init (mount) [do we really need this?]initialValueinitialize value to a predefined value or error [should this be separate values for data and error?]
Callback options:
onInitwhen first initialized (i.e. mount)onDatawhen promise has fulfilled with dataonErrorwhen promise has rejected with erroronAbortwhen promise has abortedonDestroywhen destroying the instance (i.e. unmount)
Actions:
runinvokefnabortcancel a pending promise and invokeAbortController::abortreinitializeabort and reset state toinitial
Metadata:
runCountnumber of timesrunwas invoked (automatically or manually)startedAtwhen the lastrunwas invokedfinishedAtwhen the last promise was fulfilled or rejected
This API deviates quite a bit from React Async. Notably:
promiseFnanddeferFnare combined intofnpromiseis dropped as an option. You can just pass() => promiseinstead.
Metadata
Metadata
Assignees
Labels
No labels