@aappddeevv/dynamics-client-ui
Version:
## What is it? A library to help you create great dynamics applications.
115 lines (114 loc) • 5.22 kB
TypeScript
/** Redux action management utilities. */
import { PutEffect, SelectEffect, CallEffect, TakeEffect, ActionChannelEffect } from "redux-saga/effects";
import { Action, AnyAction, ActionCreator } from "redux";
import { ThunkAction as ThunkActionX } from "redux-thunk";
export { ActionCreator as ActionCreator, Action as Action, AnyAction as AnyAction };
/** Used for functions that we also add the ACTION name to. */
export declare type WithACTION = {
ACTION: string;
};
export declare type ActionCreatorTypes<T extends Action> = MultiActionCreator<T> | WrapperActionCreator<T> | (ActionCreator<T> & WithACTION) | ActionCreator<T>;
/**
* A multi-action is an object with well-known keys whose values
* are action creators. Much the same as redux.ActionCReatorsMapObject.
*/
export interface MultiActionCreator<T extends Action = Action> {
[name: string]: ActionCreator<T> & WithACTION;
}
/** For react-thunk. */
export declare type ThunkAction = ThunkActionX<any, any, any>;
/** Redux had ActionCreatorsMapObject already there. */
export declare type ActionCreatorsMap<A extends Action = Action> = Record<string, ActionCreator<A> | WrapperActionCreator<A>>;
/** Action wrapper that has an ACTION label and a subaction data property. */
export interface WrapperActionCreator<S extends Action = Action> extends ActionCreator<Action & {
subaction: S;
}>, WithACTION {
}
/**
* Create an action creator. Returns a function that creates an action message
* with "type" type and argNames as properties on that message corresponding
* to the arguments of the function call. The actual properties are computed
* at runtime and hence, we cannot statically make a perfect return type.
*/
export declare function makeActionCreator<T extends Action = Action>(type: string, ...argNames: any[]): ActionCreator<T>;
/**
* Return an object with well-known keys that have action creators as values.
* The returned object has properties from "key" but the
* actual message type is under the property ACTION on the creator function and is
* made up of the id and key together.
*
* TODO: Convert to object syntax for input, not goofy array.
*/
export declare function createActionMap<T extends (Action & WithACTION) = (Action & WithACTION)>(id: string, prefixes: Array<{
key: string;
args: Array<string>;
}>): MultiActionCreator<T>;
/**
* An ActionCreator map with properties that match the names of actions needed
* to manage a multi-select like list of values.
*/
export interface MultiSelectActionCreator<T extends Action = Action> extends MultiActionCreator<T> {
SET_REFDATA: ActionCreator<T> & WithACTION;
SET: ActionCreator<T> & WithACTION;
ADD: ActionCreator<T> & WithACTION;
REMOVE: ActionCreator<T> & WithACTION;
CLEAR: ActionCreator<T> & WithACTION;
SET_ALL: ActionCreator<T> & WithACTION;
}
/**
* Create string ids and action creators i.e. Record<string, ActionCreator>
*
* ```
* const choices = createMultiSelect("somechoices") // returns an object
* ```
* Dispatching:
* ```
* dispatch(choices.SET_REFDATA(actionData))
* ```
* Reducing:
* ```
* function reducer(state, action) { ...
* case choices.SET_ALL.ACTION:
* const data = action.data
* ...
* }
* ```
*/
export declare function createMultiSelect<T extends Action = Action>(id: string): MultiSelectActionCreator<T & WithACTION>;
export interface SingleSelectActionCreator<T extends Action = Action> extends MultiActionCreator<T> {
SET_REFDATA: ActionCreator<T> & WithACTION;
SET: ActionCreator<T> & WithACTION;
CLEAR: ActionCreator<T> & WithACTION;
}
/**
* Create a single select set of actions.
* This is just a subset of those in a multi select, SET_REFDATA, SET and CLEAR.
*/
export declare function createSingleSelect<T extends Action = Action>(id: any): SingleSelectActionCreator<T & WithACTION>;
/**
* Create action and type for changing something. Args will be a subaction.
* Name on object will be "change.prefix" by default.
*
* @deprecated Use mkWrapper
*/
export declare const mkChange: <T extends Action = Action>(prefix: string, aname?: string) => WrapperActionCreator<T>;
/**
* Create action and type for changing something. Args will be a subaction.
* Name on object will be "wrapper.prefix".
*/
export declare const mkWrapper: <T extends Action = Action>(prefix: string) => WrapperActionCreator<T>;
/**
* Make a function from a "filterName" to create a saga
* action channel on and a handler to call with the most
* recent state. The subaction is dispatched before calling
* the handler. You this to track the a message which wraps another
* message and that needs to be detected in the saga middleware.
* filterName should be called channelName. You still need to call
* the returned function.
*
* @param {string} filterName Name of channel message type.
* @param {Function} handler (action,state) => generator
* @param {boolean} dispatchSubActon Dispatch subaction before calling the handler.
* @return generator
*/
export declare function mkSubactionSaga(filterName: string, handler: any, dispatchSubaction?: boolean): () => IterableIterator<TakeEffect | PutEffect<any> | CallEffect | SelectEffect | ActionChannelEffect>;