#
Module: "urx/src/system"#
Thinking in Systemssystems are a stateful data-processing machines which accept input through input streams, init and maintain state in depots and, in certain conditions, emit values to subscriptions through output streams. Systems can specify other systems as dependencies, and can act as singletons in the resulting dependency tree.
#
DepotsThe first, and probably the most critical part to understand are the depots mostly because they are somewhat implicit. Unlike other state management paradigms, the depots are not kept in a single data structure. Insted, depots are defined and maintained as stateful streams, stateful transfomers like combineLatest or stateful operators like[ []withLatestFrom] or scan.
Depots persist values over time. If it was not for them, the system had to re-receive its entire input state simultaneously in order to calculate the values for its output stream.
Of course, strictly speaking, it is possible to implement a pure, stateless system as a form of a complex map/reduce. urx would not mind that ;).
#
Input StreamsThe system receives updates from the rest of the world through values published in its input streams. The streams used can be either stateless (acting as means to send signals) or stateful, where the initial stream state acts as the default value for that system parameter.
The effects of the input streams are up to the system data-processing logic. It can change its depots' state, and/or emit values through its output streams.
#
Data ProcessingThe actual system behavior is exclusively implemented by applying transformers and operators to the input streams, producing the respective output streams.
In the final state the system streams are organized in a directed graph, where incoming data is routed through certain edges and nodes.
Simple systems like the one in urx by example can use a straightforward single-step transformation (in this case, combineLatest
and map
),
while complex ones can introduce multiple intermediate streams to model their logic.
#
Output StreamsThe system publishes updates to its clients (other systems or an UI bound to it) by publishing data in its output streams.
State-reflecting output streams, like sum
in the urx by example should use stateful streams as output streams.
Signal-like output should use regular, stateless streams. In general, stateless input streams tend to have a symmetrical stateless streams, and the opposite.
#
Index#
Interfaces#
Type aliases#
Functions#
Type aliases#
SystemConstructorƬ SystemConstructor<D>: (dependencies: SpecResults<D>) => System
Defined in urx/src/system.ts:101
The system constructor is a function which initializes and connects streams and returns them as a System. If the system call specifies system dependencies, the constructor receives the dependencies as an array argument.
#
Type parameters:Name | Type |
---|---|
D | SystemSpecs |
#
Functions#
initâ–¸ init<SS>(systemSpec
: SS): SR<SS>
Defined in urx/src/system.ts:193
Initializes a SystemSpec by recursively initializing its dependencies.
#
Type parameters:Name | Type |
---|---|
SS | AnySystemSpec |
#
Parameters:Name | Type | Description |
---|---|---|
systemSpec | SS | the system spec to initialize. |
Returns: SR<SS>
the System constructed by the spec constructor.
#
systemâ–¸ system<F, D>(constructor
: F, dependencies?
: D, __namedParameters?
: { singleton: boolean }): SystemSpec<D, F>
Defined in urx/src/system.ts:156
system
defines a specification of a system - its constructor, dependencies and if it should act as a singleton in a system dependency tree.
When called, system returns a SystemSpec, which is then initialized along with its dependencies by passing it to init.
#
Singletons in Dependency TreeBy default, systems will be initialized only once if encountered multiple times in the dependency tree.
In the below dependency system tree, systems b
and c
will receive the same stream instances from system a
when system d
is initialized.
If a
gets {singleton: false}
as a last argument, init
creates two separate instances - one for b
and one for c
.
#
Type parameters:Name | Type |
---|---|
F | SystemConstructor<D> |
D | SystemSpecs |
#
Parameters:Name | Type | Default value | Description |
---|---|---|---|
constructor | F | - | the system constructor function. Initialize and connect the streams in its body. |
dependencies | D | ([] as unknown) as D | the system dependencies, which the constructor will receive as arguments. Use the tup utility For TypeScript type inference to work correctly. ts const sys3 = system(() => { ... }, tup(sys2, sys1)) |
__namedParameters | { singleton: boolean } | { singleton: true } | Options |
Returns: SystemSpec<D, F>