Simple unary function that is meant to select sub-part of a state.
original shape
extracted partial shape
A tuple of latest emission, state of an observable and eventual error thrown by the observable.
null
if it hasn't started emitting yet and no default value was providedtype of the emitted value
null
determines that state is nullable, the only only other acceptable type is never
Async version of useMemo
where the factory is supposed to return a promise.
The hook returns a snapshot of the promise as if it was an observable.
type of the value generated by the async factory
async factory
dependencies of the async factory
Returns a ref
object whose current
value is always the latest value emitted by the provided observable.
Note that if the observable changes, the value is not reset. Therefore if the new observable is asynchronous, the ref will still have value of the previous observable until the new one emits.
type of the emitted value
observable to subscribe to and whose emissions should be kept in the ref
an initial value of the ref to be used while waiting for the observable to emit (if it is async)
Similar to useState
but returns an observable of the current value rather than the value itself.
Both values of the returned tuple are identity stable.
type of the state value
initial value for the returned BehaviorSubject
or a factory that generates that value
a tuple of BehaviorSubject
and a callback used to change the - or better to say to emit a new - state
A simple helper that takes a snapshot of a part of the observable
defined by the selector
.
The snapshot is recomputed when the deps
change so that an updated selector can be applied.
Note: An Object.is
equality check is applied to the selected sub-part in order to avoid unnecessary re-renders.
In other words the snapshot will be updated only in case the new emission's identity differs from the previous one's.
source observable to subscribe to
function used to select sub-part of the observable state
dependencies for the selector function
A simple hel per that takes a snapshot of a part of the observable
defined by the selector
.
The snapshot is recomputed when the deps
change so that an updated selector can be applied.
The equalityFunc
is applied to the selected sub-part in order to avoid unnecessary re-renders.
In other words the snapshot will be updated only in case the new emission differs from the previous one in the sense of equalityFunc
.
source observable to subscribe to
function used to select sub-part of the observable state
equality function to check whether the selected sub-part actually changed from the previous one
dependencies for the selector function
Takes an observable and returns its current snapshot. The snapshot consist of the latest value emitted by the observable, its state and an eventual error thrown by it.
The snapshot is updated any time the observable emits and if the new snapshot differs from the previous one, the component is re-rendered.
type of the emitted value of the source observable
source observable to subscribe to
Takes an observable and returns its current snapshot. The snapshot consist of the latest value emitted by the observable, its state and an eventual error thrown by it.
The snapshot is updated any time the observable emits and if the new snapshot differs from the previous one, the component is re-rendered.
source observable to subscribe to
Takes an observable and returns its current snapshot. The snapshot consist of the latest value emitted by the observable, its state and an eventual error thrown by it.
The snapshot is updated any time the observable emits and if the new snapshot differs from the previous one, the component is re-rendered.
source observable to subscribe to
default value to be returned as part of the snapshot while waiting for the observable to emit, or when the observable is nullish
Takes an observable and returns its current snapshot. The snapshot consist of the latest value emitted by the observable, its state and an eventual error thrown by it.
The snapshot is updated any time the observable emits and if the new snapshot differs from the previous one, the component is re-rendered.
source observable to subscribe to
Takes an observable and returns its current snapshot. The snapshot consist of the latest value emitted by the observable, its state and an eventual error thrown by it.
The snapshot is updated any time the observable emits and if the new snapshot differs from the previous one, the component is re-rendered.
source observable to subscribe to
Takes an observable and returns its current snapshot. The snapshot consist of the latest value emitted by the observable, its state and an eventual error thrown by it.
The snapshot is updated any time the observable emits and if the new snapshot differs from the previous one, the component is re-rendered.
source observable to subscribe to
default value to be returned as part of the snapshot while waiting for the observable to emit, or when the observable is nullish
A simple helper that subscribes to the observable with the provided observer,
optionally resubscribes whenever any of the deps
changes, and finally unsubscribes
when the component unmounts.
type of the emission of the observable we are subscribing to
source observable to subscribe to
observer to subscribe with
dependencies of the observer
TODO Needs more love: https://github.com/salsita/spicy-hooks/issues/13
Converts the provided observable into a BehaviorSubject
.
If the source observable is synchronous, its next emission will be immediately available through getValue()
method of the returned BehaviorSubject
.
type of the value emitted by the source observable
source observable
TODO Needs more love: https://github.com/salsita/spicy-hooks/issues/13
Converts the provided observable into a BehaviorSubject
.
If the source observable is synchronous, its next emission will be immediately available through getValue()
method of the returned BehaviorSubject
.
source observable
TODO Needs more love: https://github.com/salsita/spicy-hooks/issues/13
Converts the provided observable into a BehaviorSubject
.
If the source observable is synchronous, its next emission will be immediately available through getValue()
method of the returned BehaviorSubject
.
source observable
default value to be provided through getValue()
until the source observable emits
TODO Needs more love: https://github.com/salsita/spicy-hooks/issues/13
Converts the provided observable into a BehaviorSubject
.
If the source observable is synchronous, its next emission will be immediately available through getValue()
method of the returned BehaviorSubject
.
source observable
TODO Needs more love: https://github.com/salsita/spicy-hooks/issues/13
Converts the provided observable into a BehaviorSubject
.
If the source observable is synchronous, its next emission will be immediately available through getValue()
method of the returned BehaviorSubject
.
source observable
TODO Needs more love: https://github.com/salsita/spicy-hooks/issues/13
Converts the provided observable into a BehaviorSubject
.
If the source observable is synchronous, its next emission will be immediately available through getValue()
method of the returned BehaviorSubject
.
source observable
default value to be provided through getValue()
until the source observable emits
Binds the provided unary function to an emitted value as its only argument. Emits a parameter less function.
type of the source observable
return type of the provided function
a function to bind the emitted value to
Makes a cold observable from any emitted parameterless function that returns ObservableInput
.
This operator is especially handy for turning asynchronous functions into cold observables.
Subscribes to any emitted observable, but "cancels" it immediately when another one arrives. Canceling means:
cancelError
is specified and different from undefined
)The observables are re-emitted immediately as hot.
Warning: The source observable is always subscribed to, therefore this concurrency strategy cannot prevent eventual side-effects when cancelling.
type of both the accepted and emitted observable
when provided the re-emitted observable will throw the provided error instead of completing when it is cancelled
Turns the first incoming observable hot and ignores any further observable until the first completes (or fails). Once that happens the operator is ready to accept new observables.
The hot observables are emitted, the others not.
type of both the accepted and emitted observable
Ensures that the first emitted observable will become hot. Latest succeeding emitted observable is queued until previous completes. Any further emitted observable replaces the previously queued one.
The observables are emitted as soon as they become hot.
type of both the accepted and emitted observable
Queues all incoming observable and turns each of them hot after the previous completes.
The observables are emitted as soon as they become hot.
type of both the accepted and emitted observable
Works just like shareReplay(1)
, but makes sure that it completely resets after all subscribers are gone.
type of observable to be multicast
Create a dummy async observable that emits a single value
after the specified delay
and then completes.
the value to emit or -1
to throw an exception instead
delay in milliseconds before the observable should emit
optional string array where a simple log messages get appended as the flow of the observable proceeds
Retrieves next emit of an observable in a synchronous operation. Fails if the observable throws an exception, if it completes before emitting or if it is not synchronous.
type of the observable value
source observable to get a synchronous emit from
Check whether the provided Observable
is an instance of BehaviorSubject
.
type of the observable value
observable to be checked
Generated using TypeDoc
@spicy-hooks/observables
API reference
This is a detailed API reference of the
@spicy-hooks/observables
package.For high-level information about this package and installation instructions, please see our GitHub repository.