Public StateHandler constructor. As the StateHandler is
a Singleton class, this constructor is only invoked the first
time it is targeted by the new
operator. Upon this first invocation, the
worker property is assigned an instance of the StateWorker
Thread while using the supplied source
, if any.
Optional
source: stringAn optional Kernel.Module source
.
Optional
scope: stringAn optionally scope
d ServiceWorkerRegistration.
A ReferenceError when the environment is incompatible.
Static
Private
loaderPrivate static ReplaySubject used as the StateHandler loader. This loader emits once after the StateHandler has been successfully initialized.
Readonly
workerThe worker Thread is the main background workhorse, depending
on the environment, either a navigator.serviceWorker
is register
ed or a
new require('worker_threads').Worker()
NodeJS equivalent will be forked.
Private
Readonly
kernelStatic
[observable]Static Symbol.observable
method returning a Subscribable. The
returned Subscribable mirrors the private loader and is
used for initializations after the StateHandler has been
successfully initialized.
A Subscribable emitting this StateHandler.
Subscribe to the StateHandler:
import { StateHandler } from '@sgrud/state';
import { from } from 'rxjs';
from(StateHandler).subscribe(console.log);
Public deploy method which defers the deployment of the supplied
store
under the supplied handle
to the StateWorker. For
convenience, instead of invoking this deploy method manually, the
Stateful decorator should be considered.
The extending Store InstanceType.
An Observable of the Store deployment.
Public deprecate method which defers to an invocation of the backing
deprecate method of the StateWorker to deprecate the
Store represented by the supplied handle
.
The Bus.Handle representing the Store.
An Observable of the Store deprecation.
Public dispatch method which defers the dispatching of the supplied
action
to the Store represented by the the supplied handle
to
the StateWorker. For convenience, instead of manually invoking this
dispatch method manually, the Stateful decorator should be
considered.
The extending Store InstanceType.
The Bus.Handle representing the Store.
Rest
...action: Store.Action<T>A type-guarded Store.Action to dispatch.
An Observable of the resulting Store.State.
Public implant method which defers the implantation of the supplied
effect
under the supplied locate
to the StateWorker. For
convenience, instead of invoking this implant method manually, the
Implant decorator should be considered.
The Store.Effect locate
type.
An Observable of the Store implantation.
Public invalidate method which defers to an invocation of the backing
invalidate method of the StateWorker to invalidate the
Effect represented by the supplied locate
.
The Store.Effect locate
type.
An Observable of the Effect invalidation.
Generated using TypeDoc
The StateHandler Singleton class provides the means to interact with an automatically registered ServiceWorker, when instantiated in a browser environment or, when the StateHandler is instantiated within a NodeJS environment, a
new require('worker_threads').Worker()
is forked. Within either of these Threads the StateWorker is executed and handles the deployment of Stores and dispatching Store.Actions against them. The same goes for Effects, whose implantation the StateWorker handles.The functionality provided by the StateHandler is best consumed by applying on of the Stateful or Implant decorators, as those provide easier and higher-level interfaces to the functionality provided by this Singleton class.
Decorator
Singleton
See
StateWorker