/** * This file provides utility functions for creating reducers that manage async data (in other * words, data fetched via requests to the server). * * Data is stored using the following schema: * * { * isLoading {boolean} - True when an async fetch operation is in progress for the data. Allows * us to avoid duplicate simultaneous fetch operations and to provide feedback to the user * during load operations (loading animations) * error {*} - If the most recent async fetch operation failed, this field will hold that error * lastUpdated {Date} - The last time the data was updated. Allows us to detect data that has yet * to be fetched as well as stale data * data {*} - The actual data * } * * Lists of data are also supported. * * Note that the generated reducers all expects actions to be in the Flux Standard Action (FSA) format: * https://github.com/acdlite/flux-standard-action#example. */ import type { DataAction, ErrorAction, ReduxAction, SubstateItemData, SubstateListData } from "./types"; /** * Returns a reducer that manages an async data item. * * @template [I=any] The type for an item returned by these selectors * @template [E=any] The error type for an item's failed load * @template [P=I] The action payload type * @param {function(I, ReduxAction

): I} [reduceFn] A function that produces a * new data entry, given the data entry from the current state and the action object. By default, * it is the identity function, which is only appropriate in cases where P = I; if you define an * explicit P type parameter, then you must also define this function parameter. * @return {function(SubstateItemData, ReduxAction): SubstateItemData} The reducer */ export declare const newAsyncDataReducer: (reduceFn?: (state: I, action: DataAction

) => I) => (state: SubstateItemData, action: DataAction

| ErrorAction) => SubstateItemData; /** * Returns a reducer that stores/replaces a single item in an async data list. * * @template [I=any] The type for an item returned by these selectors * @template [E=any] The error type for an item's failed load * @param {function(P | E): string} keyFn A function that returns a unique key for the list item * @param {function(I, ReduxAction

): I} [itemReduceFn] A function that produces a * new data entry, given the data entry from the current state and the action object. By default, * it is the identity function, which is only appropriate in cases where P = I; if you define an * explicit P type parameter, then you must also define this function parameter. * @return {function(SubstateListData, ReduxAction): SubstateListData} The reducer */ export declare const newAsyncListItemReducer: (keyFn: (payload: E | P) => string, reduceFn?: (state: I, action: ReduxAction

) => I) => (state: SubstateListData, action: DataAction

| ErrorAction) => SubstateListData; /** * Returns a reducer that deletes a single item in an async data list. * * @template [I=any] The type for an item returned by these selectors * @template [E=any] The error type for an item's failed load * @template [P=any] The action payload type. May likely be *like* `I`, similar to the * newAsyncDataReducer or newAsyncListItemReducer versions, but the only requirement is that `keyFn` * be able to extract the correct key from the payload. * @param {function(P): string} keyFn - A function that returns a unique key for the list item * @return {function(SubstateListData, action: ReduxAction

)} - The reducer */ export declare const newAsyncListItemDeleteReducer: (keyFn: (payload: P) => string) => (state: SubstateListData, action: ReduxAction

) => SubstateListData; /** * Returns a reducer that takes a list payload and stores it as an object, where each value is of * the format described at the top of this file. * * @template [I=any] The type for an item returned by these selectors * @template [E=any] The error type for an item's failed load * @template [LE=E] The error type for the list's failed load. May or may not be the same as `E`. * @param {function(I): string} keyFn - A function that returns a unique key for every * payload list item * @param {function(SubstateItemData, ReduxAction): I} [itemReduceFn] - A function that * produces a new data entry for a single item in the list, given the data entry from the current * item state and an action containing the item as its payload * @return {function(SubstateListData, ReduxAction): SubstateListData} - The reducer */ export declare const newAsyncListReducer: (keyFn: (payload: P) => string, itemReduceFn?: (state: SubstateItemData, action: ReduxAction

) => I) => (state: SubstateListData, action: DataAction | ErrorAction) => SubstateListData;