UNPKG

test-jsonforms-react-spectrum-renderers

Version:

React Spectrum Renderer Set for JSONForms

175 lines (174 loc) 7.82 kB
export interface Action<T = any> { type: T; } /** * An Action type which accepts any other properties. * This is mainly for the use of the `Reducer` type. * This is not part of `Action` itself to prevent types that extend `Action` from * having an index signature. */ export interface AnyAction extends Action { [extraProps: string]: any; } /** * A *dispatching function* (or simply *dispatch function*) is a function that * accepts an action or an async action; it then may or may not dispatch one * or more actions to the store. * * We must distinguish between dispatching functions in general and the base * `dispatch` function provided by the store instance without any middleware. * * The base dispatch function *always* synchronously sends an action to the * store's reducer, along with the previous state returned by the store, to * calculate a new state. It expects actions to be plain objects ready to be * consumed by the reducer. * * Middleware wraps the base dispatch function. It allows the dispatch * function to handle async actions in addition to actions. Middleware may * transform, delay, ignore, or otherwise interpret actions or async actions * before passing them to the next middleware. * * @template A The type of things (actions or otherwise) which may be * dispatched. */ export declare type Dispatch<A extends Action = AnyAction> = <T extends A>(action: T) => T; /** * A store is an object that holds the application's state tree. * There should only be a single store in a Redux app, as the composition * happens on the reducer level. * * @template S The type of state held by this store. * @template A the type of actions which may be dispatched by this store. */ export interface Store<S = any, A extends Action = AnyAction> { /** * Dispatches an action. It is the only way to trigger a state change. * * The `reducer` function, used to create the store, will be called with the * current state tree and the given `action`. Its return value will be * considered the **next** state of the tree, and the change listeners will * be notified. * * The base implementation only supports plain object actions. If you want * to dispatch a Promise, an Observable, a thunk, or something else, you * need to wrap your store creating function into the corresponding * middleware. For example, see the documentation for the `redux-thunk` * package. Even the middleware will eventually dispatch plain object * actions using this method. * * @param action A plain object representing “what changed”. It is a good * idea to keep actions serializable so you can record and replay user * sessions, or use the time travelling `redux-devtools`. An action must * have a `type` property which may not be `undefined`. It is a good idea * to use string constants for action types. * * @returns For convenience, the same action object you dispatched. * * Note that, if you use a custom middleware, it may wrap `dispatch()` to * return something else (for example, a Promise you can await). */ dispatch: Dispatch<A>; /** * Reads the state tree managed by the store. * * @returns The current state tree of your application. */ getState(): S; /** * Adds a change listener. It will be called any time an action is * dispatched, and some part of the state tree may potentially have changed. * You may then call `getState()` to read the current state tree inside the * callback. * * You may call `dispatch()` from a change listener, with the following * caveats: * * 1. The subscriptions are snapshotted just before every `dispatch()` call. * If you subscribe or unsubscribe while the listeners are being invoked, * this will not have any effect on the `dispatch()` that is currently in * progress. However, the next `dispatch()` call, whether nested or not, * will use a more recent snapshot of the subscription list. * * 2. The listener should not expect to see all states changes, as the state * might have been updated multiple times during a nested `dispatch()` before * the listener is called. It is, however, guaranteed that all subscribers * registered before the `dispatch()` started will be called with the latest * state by the time it exits. * * @param listener A callback to be invoked on every dispatch. * @returns A function to remove this change listener. */ subscribe(listener: () => void): Unsubscribe; /** * Replaces the reducer currently used by the store to calculate the state. * * You might need this if your app implements code splitting and you want to * load some of the reducers dynamically. You might also need this if you * implement a hot reloading mechanism for Redux. * * @param nextReducer The reducer for the store to use instead. */ replaceReducer(nextReducer: Reducer<S, A>): void; /** * Interoperability point for observable/reactive libraries. * @returns {observable} A minimal observable of state changes. * For more information, see the observable proposal: * https://github.com/tc39/proposal-observable */ [Symbol.observable](): Observable<S>; } /** * A minimal observable of state changes. * For more information, see the observable proposal: * https://github.com/tc39/proposal-observable */ export declare type Observable<T> = { /** * The minimal observable subscription method. * @param {Object} observer Any object that can be used as an observer. * The observer object should have a `next` method. * @returns {subscription} An object with an `unsubscribe` method that can * be used to unsubscribe the observable from the store, and prevent further * emission of values from the observable. */ subscribe(observer: Observer<T>): { unsubscribe: Unsubscribe; }; [Symbol.observable](): Observable<T>; }; /** * An Observer is used to receive data from an Observable, and is supplied as * an argument to subscribe. */ export declare type Observer<T> = { next?(value: T): void; }; /** * A *reducer* (also called a *reducing function*) is a function that accepts * an accumulation and a value and returns a new accumulation. They are used * to reduce a collection of values down to a single value * * Reducers are not unique to Redux—they are a fundamental concept in * functional programming. Even most non-functional languages, like * JavaScript, have a built-in API for reducing. In JavaScript, it's * `Array.prototype.reduce()`. * * In Redux, the accumulated value is the state object, and the values being * accumulated are actions. Reducers calculate a new state given the previous * state and an action. They must be *pure functions*—functions that return * the exact same output for given inputs. They should also be free of * side-effects. This is what enables exciting features like hot reloading and * time travel. * * Reducers are the most important concept in Redux. * * *Do not put API calls into reducers.* * * @template S The type of state consumed and produced by this reducer. * @template A The type of actions the reducer can potentially respond to. */ export declare type Reducer<S = any, A extends Action = AnyAction> = (state: S | undefined, action: A) => S; /** * Function to remove listener added by `Store.subscribe()`. */ export declare type Unsubscribe = () => void;