core
Index
Classes
Functions
- atom
- batch
- combineAtoms
- compute
- createAtomSubject
- createScope
- createStore
- createStoreUpdates
- declareStateUpdates
- declareStore
- defaultEquals
- destroySignal
- effect
- getAtomName
- getSignalName
- isAtom
- isSignal
- isSignalDestroyed
- isSignalSubscribed
- keepLastValue
- mapAtom
- mergeAtoms
- mixSignals
- objectEquals
- runEffects
- signal
- signalChanges
- syncEffect
Interfaces
Type Aliases
Type Aliases
Atom
Type parameters
- T
AtomOptions
Options passed to the atom
creation function.
Type parameters
- T
Type declaration
optionalequal?: ValueEqualityFn<T>
A comparison function which defines equality for atom values.
optionalname?: string
Atom's name
optionalonDestroy?: () => void
Callback is called when the store is destroyed.
Callback is called when the store is destroyed.
Returns void
AtomSubject
An atom that emits values and errors.
Type parameters
- T
Computation
A pure function that returns a value.
Type parameters
- T
Type declaration
Returns T
ComputeOptions
Options for compute
Type parameters
- T
Type declaration
optionalequal?: ValueEqualityFn<T>
A function to determine if two values are equal. Defaults to
Object.is
.optionalname?: string
Atom's name
DeclareStoreOptions
DestroyableAtom
An Atom that can be destroyed
Type parameters
- T
EffectAction
Type parameters
- T
- R
Type declaration
Parameters
value: T
context: EffectContext
Returns R | Promise<R>
EffectContext
Type declaration
cleanup: function
Parameters
callback: () => void
Returns void
EffectOptions
Options for an effect
Type declaration
optionalsync?: boolean
EffectSubscription
A reactive effect, which can be manually destroyed.
Type parameters
- R
ScopeTeardown
A resource which can be unsubscribed from or destroyed
SharedScope
SharedScope
and Scope
types allow to distinct which third-party code can invoke destroy()
method.
Signal
Signal is an event emitter. It can be called to notify listeners of events.
Type parameters
- Event
SignalOptions
Options passed to the signal
creation function.
Type parameters
- TEvent
Type declaration
optionalname?: string
Signal's name
optionalonDestroy?: () => void
Callback is called when the signal is destroyed.
Callback is called when the signal is destroyed.
Returns void
optionalonEvent?: (event: TEvent) => void
Callback is called at the same time when the signal is called
Callback is called at the same time when the signal is called
Parameters
event: TEvent
Returns void
optionalonSubscribe?: () => void
Callback is called when an effect is subscribed.
Callback is called when an effect is subscribed.
Returns void
optionalonUnsubscribe?: (isEmpty: boolean) => void
Callback is called when an effect is unsubscribed.
Callback is called when an effect is unsubscribed.
Parameters
isEmpty: boolean
Returns void
optionalsync?: boolean
If true, the signal forces usage of "sync" scheduler.
StateMutation
A function to update a state.
It is recommended to return a new state or the previous one.
Actually, the function can change the state in place, but it is responsible
for a developer to provide comparator
function to the store which handles
the changes.
For making changes use a currying function to provide arguments:
const addPizzaToCart = (name: string): StateMutation<Array<string>> =>
(state) => ([...state, name]);
Type parameters
- State
Type declaration
Parameters
state: State
a previous state
Returns State
StateUpdates
A record of factories which create state mutations.
Type parameters
- State
Store
StoreFactory
Factory function for creating a store
Type parameters
- State
- Updates: StateUpdates<State>
Type declaration
Parameters
optionalinitialState: FactoryStateArg<State>
Initial state
optionaloptions: AtomOptions<State>
Options for the store
Returns Store<State, Updates>
Parameters
optionalinitialState: FactoryStateArg<State>
Initial state
optionaloptions: AtomOptions<State>
Options for the store
Returns Store<State, Updates>
readonlyinitialState: State
Initial state
readonlyupdates: Updates
State mutators
StoreUpdate
Function which changes a state of the store
Type parameters
- Args: unknown[]
Type declaration
Parameters
rest...args: Args
Returns void
StoreUpdates
ValueEqualityFn
A comparison function which can determine if two values are equal.
Type parameters
- T
Type declaration
Parameters
a: T
b: T
Returns boolean
A reactive value which notifies consumers of any changes.
Atoms are functions which returns their current value. To access the current value of an atom, call it.