DynamicValue Operators¶
Dynamic value operators are functions which create and transform dynamic
values. There are useful in combination with the pipe
property of the
PrefixComponentBase component.
Dynamic value operators can be thought of as asynchronous analogues of standard control flow constructs. For instance,
the filter function removes values from the stream of values emitted by a dynamic value,
the map function transforms values received and sent by a dynamic value,
the switchMap function can be used to dynamically switch between dynamic values based on the value of another dynamic value. This can be thought of as the asynchronous analog of
if (valueA) { return valueB; } else { return valueC; }
the resolve function can be used to transform values received using an async function and
the combineLatest function can be used to combine the values emitted by a list of dynamic values into one array of values.
filter¶
-
filter
(dv, predicate)¶ Transform the input dynamic value and emits a new DynamicValue which emits only those value for which the predicate is true.
- Arguments
dv (DynamicValue) –
predicate (function) – The predicate function. If it returns false, the corresponding value is ignored.
- Returns
DynamicValue –
map¶
-
map
(dv, transform, inverse)¶ Transform the input dynamic value and emits a new DynamicValue which emits each value of the input transformed with f. If an inverse transform is also given, calling set(X) on the resulting DynamicValue will use the inverse transform and call dv.set(inverse(X)).
- Arguments
dv (DynamicValue) –
transform (function) – Transformation function for values.
inverse (function) – Optional inverse transformation function. It not specified, the resulting DynamicValue does not support set().
- Returns
DynamicValue –
switchMap¶
-
switchMap
(dv, projection)¶ switchMap can be used to between different DynamicValues based on the value emitted from another DynamicValue.
- Arguments
dv (DynamicValue) –
projection (function) – This function is called for each value emitted by the input DynamicValue. The DynamicValue returned will then be subscribed to. If the projection function returned null, the value is ignored.
- Returns
DynamicValue –
resolve¶
-
resolve
(dv, projection, parallel=false)¶ This transformation can be used to start an asynchronous task for each value emitted. The returned DynamicValue will emit one value for each result of a resolved task. Tasks which fail will be caught and generate a warning in the console.
- Arguments
dv (DynamicValue) – The input DynamicValue.
projection (function) – Transformation function for values.
parallel (boolean) – If true, each value will spawn a task and all their values will be emitted in order. If false, only one task may be running at the same time.
- Returns
DynamicValue –