UNPKG

dreamstate

Version:

Store management library based on react context and observers

28 lines (25 loc) 1.01 kB
import { LoadableStore } from '../core/storing/LoadableStore.js'; /** * Creates a loadable value, which is useful when the context value has error/loading states. * The loadable value can represent different states: loading, ready, or error. * * @template T The type of the value being loaded. * @template E The type of the error (defaults to `Error`). * @param {T | null} [value] The initial value or `null` if not yet loaded. * @param {boolean} [isLoading] A flag indicating whether the value is in a loading state. * @param {E | null} [error] The error if the value failed to load, or `null` if no error. * @returns {ILoadable<T, E>} A loadable value utility representing the current state of the value. */ function createLoadable(value, isLoading, error) { if (value === void 0) { value = null; } if (isLoading === void 0) { isLoading = false; } if (error === void 0) { error = null; } return new LoadableStore(value, isLoading, error); } export { createLoadable };