Class: DataItemUtils
Defined in: src/sdk/data/DataItemUtils.ts:10
Experimental
A utility class for working with DataItems.
Constructors
Constructor
new DataItemUtils():
DataItemUtils
Experimental
Returns
DataItemUtils
Methods
createEquals()
staticcreateEquals<T>(valueEqualityFunc): (a,b) =>boolean
Defined in: src/sdk/data/DataItemUtils.ts:45
Experimental
Creates a function that evaluates the equality of two data items given value equality semantics defined by a supplied function.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
valueEqualityFunc | (a, b) => boolean | DataItemUtils.defaultValueEquals | The function to use to check whether two data item values are equal. Defaults to a function that implements default equality semantics: two values a and b are equal if and only if the strict equality operator (===) evaluates to true for a and b, or both a and b are the numeric value NaN. |
Returns
A function that evaluates the equality of two data items given the value equality semantics defined by the specified function.
(
a,b):boolean
Parameters
| Parameter | Type |
|---|---|
a | Readonly<DataItem<T>> |
b | Readonly<DataItem<T>> |
Returns
boolean
createIsValid()
staticcreateIsValid<S>(validStatuses):DataItemStatusGuard<S>
Defined in: src/sdk/data/DataItemUtils.ts:81
Experimental
Creates a predicate that can be used with DataItemUtils.valueOr or DataItemUtils.isValid.
Type Parameters
| Type Parameter |
|---|
S extends DataItemStatus |
Parameters
| Parameter | Type | Description |
|---|---|---|
validStatuses | readonly S[] | An array of statuses that should be considered valid. |
Returns
DataItemStatusGuard<S>
The new predicate.
defaultEquals()
staticdefaultEquals(a,b):boolean
Defined in: src/sdk/data/DataItemUtils.ts:31
Experimental
Checks whether two data items are equal using default equality semantics for data item values: values for two data
items a.value and b.value are equal if and only if the strict equality operator (===) evaluates to true
for a.value and b.value, or both a.value and b.value are the numeric value NaN.
Parameters
| Parameter | Type | Description |
|---|---|---|
a | Readonly<DataItem<unknown>> | The first data item to check. |
b | Readonly<DataItem<unknown>> | The second data item to check. |
Returns
boolean
Whether the two specified data items are equal using default equality semantics for their data item values.
defaultIsValid()
staticdefaultIsValid(dataItem): dataItem is Readonly<FilledDataItem<any> & { status: Normal | Testing }>
Defined in: src/sdk/data/DataItemUtils.ts:72
Experimental
Checks if a data item status is DataItemStatus.Normal or DataItemStatus.Testing.
Parameters
| Parameter | Type | Description |
|---|---|---|
dataItem | Readonly<DataItem<any>> | The data item to check. |
Returns
dataItem is Readonly<FilledDataItem<any> & { status: Normal | Testing }>
true if the data item is valid.
defaultValueEquals()
staticdefaultValueEquals(a,b):boolean
Defined in: src/sdk/data/DataItemUtils.ts:62
Experimental
Checks whether two data item values are equal using default equality semantics: two values a and b are equal
if and only if the strict equality operator (===) evaluates to true for a and b, or both a and b are
the numeric value NaN.
Parameters
| Parameter | Type | Description |
|---|---|---|
a | unknown | The first data item value to check. |
b | unknown | The second data item value to check. |
Returns
boolean
Whether the two specified values are equal using default equality semantics.
emptyItem()
staticemptyItem():EmptyDataItem
Defined in: src/sdk/data/DataItemUtils.ts:15
Experimental
Creates a new empty data item.
Returns
A new empty data item.
isValid()
Call Signature
staticisValid(dataItem): dataItem is Readonly<FilledDataItem<any> & { status: Normal | Testing }>
Defined in: src/sdk/data/DataItemUtils.ts:90
Experimental
Checks if a data item is valid, according to the isValid predicate.
Parameters
| Parameter | Type | Description |
|---|---|---|
dataItem | Readonly<DataItem<any>> | The data item to check. |
Returns
dataItem is Readonly<FilledDataItem<any> & { status: Normal | Testing }>
Whether the data item is valid (status is DataItemStatus.Normal or DataItemStatus.Testing).
Call Signature
staticisValid<S>(dataItem,isValid):dataItem is Readonly<DataItemOfStatus<any, S>>
Defined in: src/sdk/data/DataItemUtils.ts:97
Experimental
Checks if a data item is valid, according to the isValid predicate.
Type Parameters
| Type Parameter |
|---|
S extends DataItemStatus |
Parameters
| Parameter | Type | Description |
|---|---|---|
dataItem | Readonly<DataItem<any>> | The data item to check. |
isValid | DataItemStatusGuard<S> | An isValid predicate created by DataItemUtils.createIsValid. |
Returns
dataItem is Readonly<DataItemOfStatus<any, S>>
Whether the data item is valid according to isValid.
Call Signature
staticisValid(dataItem,isValid?):boolean
Defined in: src/sdk/data/DataItemUtils.ts:105
Experimental
Checks if a data item is valid, according to the isValid predicate.
Parameters
| Parameter | Type | Description |
|---|---|---|
dataItem | Readonly<DataItem<any>> | The data item to check. |
isValid? | DataItemStatusGuard<DataItemStatus> | An isValid predicate created by DataItemUtils.createIsValid. Defaults to a validator accepting DataItemUtils.valueOr or DataItemUtils.isValid. |
Returns
boolean
Whether the data item is valid according to isValid.
valueOr()
staticvalueOr<T,D>(dataItem,defaultValue,isValid):T|D
Defined in: src/sdk/data/DataItemUtils.ts:120
Experimental
Gets the value of the data item is the status is valid (Normal or Testing), or else a default value.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | - |
D | T |
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
dataItem | Readonly<DataItem<T>> | undefined | The data item to use. |
defaultValue | D | undefined | The default value returned when the data item is invalid. |
isValid | DataItemStatusGuard<Normal | Failed | NoComputedValue | Testing> | DataItemUtils.defaultIsValid | An isValid predicate created by DataItemUtils.createIsValid. Defaults to a predicate that accepts DataItemStatus.Normal or DataItemStatus.Testing as valid. |
Returns
T | D
The valid value, or the default value.