Class: DataItemUtils
Defined in: src/sdk/data/DataItemUtils.ts:6
A utility class for working with DataItems.
Constructors
Constructor
new DataItemUtils():
DataItemUtils
Returns
DataItemUtils
Methods
createEquals()
staticcreateEquals<T>(valueEqualityFunc): (a,b) =>boolean
Defined in: src/sdk/data/DataItemUtils.ts:42
Creates a function that evaluates the equality of two data items given value equality semantics defined by a supplied function.
Type Parameters
| Type Parameter | Description |
|---|---|
T | The value type of the data items to compare. |
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
createIsStatusValid()
staticcreateIsStatusValid<S>(validStatuses): (status) =>status is S
Defined in: src/sdk/data/DataItemUtils.ts:103
Creates a function that checks whether data item statuses are valid.
Type Parameters
| Type Parameter | Description |
|---|---|
S extends DataItemStatus | The type of the data item statuses that should be considered valid. |
Parameters
| Parameter | Type | Description |
|---|---|---|
validStatuses | readonly S[] | An array of data item statuses that should be considered valid. The returned function will consider a data item status to be valid if and only if it is contained in this array. |
Returns
A function that checks whether data item statuses are valid given the specified array of valid statuses.
(
status):status is S
Parameters
| Parameter | Type |
|---|---|
status | DataItemStatus |
Returns
status is S
createIsValid()
staticcreateIsValid<S>(validStatuses):DataItemStatusGuard<S>
Defined in: src/sdk/data/DataItemUtils.ts:92
Creates a function that checks whether data items are valid.
Type Parameters
| Type Parameter | Description |
|---|---|
S extends DataItemStatus | The type of the data item statuses that should be considered valid. |
Parameters
| Parameter | Type | Description |
|---|---|---|
validStatuses | readonly S[] | An array of data item statuses that should be considered valid. The returned function will consider a data item to be valid if and only if its status is contained in this array. |
Returns
A function that checks whether data items are valid given the specified array of valid statuses.
defaultEquals()
staticdefaultEquals(a,b):boolean
Defined in: src/sdk/data/DataItemUtils.ts:27
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.
defaultIsStatusValid()
staticdefaultIsStatusValid(status): status is Normal | Testing
Defined in: src/sdk/data/DataItemUtils.ts:81
Checks if a data item status is either DataItemStatus.Normal or DataItemStatus.Testing.
Parameters
| Parameter | Type | Description |
|---|---|---|
status | DataItemStatus | The data item status to check. |
Returns
status is Normal | Testing
Whether the specified data item's status is either DataItemStatus.Normal or DataItemStatus.Testing.
defaultIsValid()
staticdefaultIsValid(dataItem): dataItem is Readonly<FilledDataItem<unknown> & { status: Normal | Testing }>
Defined in: src/sdk/data/DataItemUtils.ts:71
Checks if a data item is valid. A valid data item's status is either DataItemStatus.Normal or DataItemStatus.Testing.
Parameters
| Parameter | Type | Description |
|---|---|---|
dataItem | Readonly<DataItem<unknown>> | The data item to check. |
Returns
dataItem is Readonly<FilledDataItem<unknown> & { status: Normal | Testing }>
Whether the specified data item's status is either DataItemStatus.Normal or DataItemStatus.Testing.
defaultValueEquals()
staticdefaultValueEquals(a,b):boolean
Defined in: src/sdk/data/DataItemUtils.ts:59
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:11
Creates a new empty data item.
Returns
A new empty data item.
valueOr()
staticvalueOr<Item,D>(dataItem,defaultValue,isValid):DataItemValueType<Item> |D
Defined in: src/sdk/data/DataItemUtils.ts:118
Gets the value of a data item if it is valid or a default value if it is not valid.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
Item extends Readonly<DataItem<unknown>> | - | The type of the data item for which to get a value. |
D | DataItemValueType<Item> | The type of the default value. |
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
dataItem | Item | undefined | The data item for which to get a value. |
defaultValue | D | undefined | The default value returned when the data item is invalid. |
isValid | DataItemStatusGuard<Normal | Failed | NoComputedValue | Testing> | DataItemUtils.defaultIsValid | A function that checks whether the data item is valid. Defaults to a function that considers a data item to be valid if and only if its status is DataItemStatus.Normal or DataItemStatus.Testing. |
Returns
DataItemValueType<Item> | D
The value of the specified data item if it is valid (according to the isValid argument), or the
specified default value if the item is invalid.