Break out actions and payloads to their own files

The definitions take up a lot of space which makes it hard to see the dispatcher class, so break them out.
This commit is contained in:
Travis Ralston 2020-05-13 20:46:00 -06:00
parent 90a898d03f
commit 8c72c27da9
6 changed files with 87 additions and 52 deletions

View file

@ -17,55 +17,8 @@ limitations under the License.
*/
import { Dispatcher } from "flux";
export enum Action {
// TODO: Populate with actual actions
}
// Dispatcher actions also extend into any arbitrary string, so support that.
export type DispatcherAction = Action | string;
/**
* The base dispatch type exposed by our dispatcher.
*/
export interface ActionPayload {
[property: string]: any; // effectively makes this 'extends Object'
action: DispatcherAction;
}
/**
* The function the dispatcher calls when ready for an AsyncActionPayload. The
* single argument is used to start a dispatch. First the dispatcher calls the
* outer function, then when the called function is ready it calls the cb
* function to issue the dispatch. It may call the callback repeatedly if needed.
*/
export type AsyncActionFn = (cb: (action: ActionPayload) => void) => void;
/**
* An async version of ActionPayload
*/
export class AsyncActionPayload implements ActionPayload {
/**
* The function the dispatcher should call.
*/
public readonly fn: AsyncActionFn;
/**
* @deprecated Not used on AsyncActionPayload.
*/
public get action(): DispatcherAction {
return "NOT_USED";
}
/**
* Create a new AsyncActionPayload with the given ready function.
* @param {AsyncActionFn} readyFn The function to be called when the
* dispatcher is ready.
*/
public constructor(readyFn: AsyncActionFn) {
this.fn = readyFn;
}
}
import { Action } from "./actions";
import { ActionPayload, AsyncActionPayload } from "./payloads";
/**
* A dispatcher for ActionPayloads (the default within the SDK).