Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions definitions/action.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* *** MIT LICENSE ***
* -------------------------------------------------------------------------
* This code may be modified and distributed under the MIT license.
* See the LICENSE file for details.
* -------------------------------------------------------------------------
*
* @summary Definitions for redux-logic
*
* @author Alvis HT Tang <alvis@hilbert.space>
* @license MIT
* @copyright Copyright (c) 2018 - All Rights Reserved.
* -------------------------------------------------------------------------
*/

//
// ACTION
//

/* * * * * *
| The following definitions are bascially identical to |
| flux-standard-action without an extra package. It also |
| makes use of conditional type to make the type of |
| payload and meta more accurate. |
* * * * * */

/** Action as an agrument */
export type ArgumentAction<
Type extends string = string,
Payload extends object = undefined,
Meta extends object = undefined
> = ActionBasis<Type> & Partial<Action<string, object, object>>;

/** all different types of Action */
export type Action<
Type extends string = string,
Payload extends object = undefined,
Meta extends object = undefined
> =
| ErroneousAction<Type, Meta>
| (StandardAction<Type, Payload, Meta> & { error?: false });

/** Action without any error */
export type StandardAction<
Type extends string = string,
Payload extends object = undefined,
Meta extends object = undefined
> = ActionBasis<Type> & PayloadBasis<Payload> & MetaBasis<Meta>;

/** Action with an Error */
export type ErroneousAction<
Type extends string = string,
Meta extends object = undefined
> = ActionBasis<Type> & PayloadBasis<Error> & MetaBasis<Meta> & { error: true };

/* ----- Auxiliary Types ----- */

/** the most basic action object */
export interface ActionBasis<Type extends string = string> {
type: Type extends infer U ? U : string;
}

/** return an interface with payload only if it presents */
export type PayloadBasis<
Payload extends object = undefined
> = Payload extends undefined ? {} : { payload: Payload };

/** return an interface with meta only if it presents */
export type MetaBasis<Meta extends object = undefined> = Meta extends undefined
? {}
: { meta: Meta };

// ---------------------------------------- //
19 changes: 19 additions & 0 deletions definitions/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* *** MIT LICENSE ***
* -------------------------------------------------------------------------
* This code may be modified and distributed under the MIT license.
* See the LICENSE file for details.
* -------------------------------------------------------------------------
*
* @summary Definitions for redux-logic
*
* @author Alvis HT Tang <alvis@hilbert.space>
* @license MIT
* @copyright Copyright (c) 2018 - All Rights Reserved.
* -------------------------------------------------------------------------
*/

export * from './action';
export * from './logic';
export * from './middleware';
export * from './utilities';
Loading