MCPcopy Create free account
hub / github.com/async-library/react-async / init

Function init

packages/react-async/src/reducer.ts:52–71  ·  view source on GitHub ↗
({
  initialValue,
  promise,
  promiseFn,
}: {
  initialValue?: Error | T
  promise?: Promise<T>
  promiseFn?: PromiseFn<T>
})

Source from the content-addressed store, hash-verified

50}
51
52export const init = <T>({
53 initialValue,
54 promise,
55 promiseFn,
56}: {
57 initialValue?: Error | T
58 promise?: Promise<T>
59 promiseFn?: PromiseFn<T>
60}) =>
61 ({
62 initialValue,
63 data: initialValue instanceof Error ? undefined : initialValue,
64 error: initialValue instanceof Error ? initialValue : undefined,
65 value: initialValue,
66 startedAt: promise || promiseFn ? new Date() : undefined,
67 finishedAt: initialValue ? new Date() : undefined,
68 ...getStatusProps(getInitialStatus(initialValue, promise || promiseFn)),
69 counter: 0,
70 promise: neverSettle,
71 } as ReducerAsyncState<T>)
72
73export const reducer = <T>(state: ReducerAsyncState<T>, action: AsyncAction<T>) => {
74 switch (action.type) {

Callers 1

constructorMethod · 0.90

Calls 2

getStatusPropsFunction · 0.90
getInitialStatusFunction · 0.90

Tested by

no test coverage detected