newAsyncDataEnvelope()
import { newAsyncDataEnvelope } from '@dr.pogodin/react-global-state';
The newAsyncDataEnvelope() function creates a new plain JS object, satisfying the AsyncDataEnvelopeT type, and with reasonable initial values of its fields.
Its TypeScript signature is
function newAsyncDataEnvelope<DataT>(
initialData: DataT | null = null,
{ numRefs = 0, timestamp = 0 } = {},
): AsyncDataEnvelopeT<DataT>;
Generic Parameters
Arguments
initialData
— DataT | null — Optional. The initial datum to put in the envelope, if any; otherwise null (default) means to create an empty envelope.options
— object — Optional. Additional parameters:numRefs
— Initial value of the reference counter. Defaults 0.timestamp
— Initial data timestamp. Defaults 0.
Result
A new object of type AsyncDataEnvelopeT<DataT>, with initialData
assigned into its data
field; empty string assigned into its operationId
field; and its numRefs
and timestamp
initialized according to given
options
, or to their default zero values.