Skip to content

Commit

Permalink
Updated TA build in sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrwitek committed Apr 21, 2019
1 parent 674c087 commit 1fd50de
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 148 deletions.
18 changes: 9 additions & 9 deletions codesandbox/src/typesafe-actions/action.d.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import { StringType } from './type-helpers';
export declare function action<T extends StringType, E>(type: T, payload: undefined, meta: undefined, error: E): {
import { TypeConstant } from './type-helpers';
export declare function action<T extends TypeConstant, E>(type: T, payload: undefined, meta: undefined, error: E): {
type: T;
error: E;
};
export declare function action<T extends StringType, M, E>(type: T, payload: undefined, meta: M, error: E): {
export declare function action<T extends TypeConstant, M, E>(type: T, payload: undefined, meta: M, error: E): {
type: T;
meta: M;
error: E;
};
export declare function action<T extends StringType, P, E>(type: T, payload: P, meta: undefined, error: E): {
export declare function action<T extends TypeConstant, P, E>(type: T, payload: P, meta: undefined, error: E): {
type: T;
payload: P;
error: E;
};
export declare function action<T extends StringType, P, M, E>(type: T, payload: P, meta: M, error: E): {
export declare function action<T extends TypeConstant, P, M, E>(type: T, payload: P, meta: M, error: E): {
type: T;
payload: P;
meta: M;
error: E;
};
export declare function action<T extends StringType, M>(type: T, payload: undefined, meta: M): {
export declare function action<T extends TypeConstant, M>(type: T, payload: undefined, meta: M): {
type: T;
meta: M;
};
export declare function action<T extends StringType, P, M>(type: T, payload: P, meta: M): {
export declare function action<T extends TypeConstant, P, M>(type: T, payload: P, meta: M): {
type: T;
payload: P;
meta: M;
};
export declare function action<T extends StringType, P>(type: T, payload: P): {
export declare function action<T extends TypeConstant, P>(type: T, payload: P): {
type: T;
payload: P;
};
export declare function action<T extends StringType>(type: T): {
export declare function action<T extends TypeConstant>(type: T): {
type: T;
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { StringType } from './type-helpers';
interface FSA<T extends StringType, P = {}, M = {}, E = boolean> {
import { TypeConstant } from './type-helpers';
interface FSA<T extends TypeConstant, P = {}, M = {}, E = boolean> {
type: T;
payload?: P;
meta?: M;
error?: E;
}
export declare function createActionDeprecated<T extends StringType, AC extends (...args: any[]) => FSA<T>>(actionType: T, creatorFunction: AC): AC;
export declare function createActionDeprecated<T extends StringType, AC extends () => {
export declare function createActionDeprecated<T extends TypeConstant, AC extends (...args: any[]) => FSA<T>>(actionType: T, creatorFunction: AC): AC;
export declare function createActionDeprecated<T extends TypeConstant, AC extends () => {
type: T;
}>(actionType: T): AC;
export {};
6 changes: 3 additions & 3 deletions codesandbox/src/typesafe-actions/create-action.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StringType, ActionCreator } from './type-helpers';
export declare type PayloadMetaAction<T extends StringType, P, M> = P extends undefined ? M extends undefined ? {
import { TypeConstant, ActionCreator } from './type-helpers';
export declare type PayloadMetaAction<T extends TypeConstant, P, M> = P extends undefined ? M extends undefined ? {
type: T;
} : {
type: T;
Expand All @@ -12,6 +12,6 @@ export declare type PayloadMetaAction<T extends StringType, P, M> = P extends un
payload: P;
meta: M;
};
export declare function createAction<T extends StringType, AC extends ActionCreator<T> = () => {
export declare function createAction<T extends TypeConstant, AC extends ActionCreator<T> = () => {
type: T;
}>(type: T, createHandler?: (actionCallback: <P = undefined, M = undefined>(payload?: P, meta?: M) => PayloadMetaAction<T, P, M>) => AC): AC;
8 changes: 4 additions & 4 deletions codesandbox/src/typesafe-actions/create-async-action.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { StringType, ActionBuilderConstructor } from './type-helpers';
export interface AsyncActionBuilder<T1 extends StringType, T2 extends StringType, T3 extends StringType> {
import { TypeConstant, ActionBuilderConstructor } from './type-helpers';
export interface AsyncActionBuilder<T1 extends TypeConstant, T2 extends TypeConstant, T3 extends TypeConstant> {
<P1, P2, P3>(): AsyncActionBuilderConstructor<T1, T2, T3, P1, P2, P3>;
}
export declare type AsyncActionBuilderConstructor<T1 extends StringType, T2 extends StringType, T3 extends StringType, P1, P2, P3> = {
export declare type AsyncActionBuilderConstructor<T1 extends TypeConstant, T2 extends TypeConstant, T3 extends TypeConstant, P1, P2, P3> = {
request: ActionBuilderConstructor<T1, P1>;
success: ActionBuilderConstructor<T2, P2>;
failure: ActionBuilderConstructor<T3, P3>;
};
export declare function createAsyncAction<T1 extends StringType, T2 extends StringType, T3 extends StringType>(requestType: T1, successType: T2, failureType: T3): AsyncActionBuilder<T1, T2, T3>;
export declare function createAsyncAction<T1 extends TypeConstant, T2 extends TypeConstant, T3 extends TypeConstant>(requestType: T1, successType: T2, failureType: T3): AsyncActionBuilder<T1, T2, T3>;
4 changes: 2 additions & 2 deletions codesandbox/src/typesafe-actions/create-custom-action.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionCreator, StringType } from './type-helpers';
export declare function createCustomAction<T extends StringType, AC extends ActionCreator<T> = () => {
import { ActionCreator, TypeConstant } from './type-helpers';
export declare function createCustomAction<T extends TypeConstant, AC extends ActionCreator<T> = () => {
type: T;
}>(type: T, createHandler?: (type: T) => AC): AC;
79 changes: 10 additions & 69 deletions codesandbox/src/typesafe-actions/create-reducer.d.ts

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions codesandbox/src/typesafe-actions/create-standard-action.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StringType, ActionBuilderConstructor, ActionBuilderMap } from './type-helpers';
export interface ActionBuilder<T extends StringType> {
import { TypeConstant, ActionBuilderConstructor, ActionBuilderMap } from './type-helpers';
export interface ActionBuilder<T extends TypeConstant> {
<P = undefined, M = undefined>(): ActionBuilderConstructor<T, P, M>;
map<R, P = undefined, M = undefined>(fn: (payload: P, meta: M) => R): ActionBuilderMap<T, R, P, M>;
}
export declare function createStandardAction<T extends StringType>(type: T): ActionBuilder<T>;
export declare function createStandardAction<T extends TypeConstant>(type: T): ActionBuilder<T>;
4 changes: 2 additions & 2 deletions codesandbox/src/typesafe-actions/get-type.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { StringType, ActionCreator, TypeMeta } from './type-helpers';
export declare function getType<T extends StringType>(actionCreator: ActionCreator<T> & TypeMeta<T>): T;
import { TypeConstant, ActionCreator, TypeMeta } from './type-helpers';
export declare function getType<T extends TypeConstant>(actionCreator: ActionCreator<T> & TypeMeta<T>): T;
2 changes: 1 addition & 1 deletion codesandbox/src/typesafe-actions/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export { createReducer } from './create-reducer';
export { getType } from './get-type';
export { isOfType } from './is-of-type';
export { isActionOf } from './is-action-of';
export { ActionType, StateType, ActionCreator, TypeMeta } from './type-helpers';
export { TypeConstant, Action, ActionCreator, Reducer, EmptyAction, PayloadAction, MetaAction, PayloadMetaAction, EmptyAC, PayloadAC, PayloadMetaAC, TypeMeta, ActionType, StateType, } from './type-helpers';
export { createActionDeprecated } from './create-action-deprecated';
6 changes: 3 additions & 3 deletions codesandbox/src/typesafe-actions/index.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ function createReducer(initialState) {
: throwInvalidActionTypeOrActionCreator();
})
.forEach(function (type) { return (handlers[type] = actionsHandler); });
return chain;
return chainApi;
});
var chain = Object.assign(reducer, {
var chainApi = Object.assign(reducer, {
addHandler: addHandler,
});
return chain;
return chainApi;
}

function isOfType(actionTypeOrTypes, action) {
Expand Down
6 changes: 3 additions & 3 deletions codesandbox/src/typesafe-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ function createReducer(initialState) {
: throwInvalidActionTypeOrActionCreator();
})
.forEach(function (type) { return (handlers[type] = actionsHandler); });
return chain;
return chainApi;
});
var chain = Object.assign(reducer, {
var chainApi = Object.assign(reducer, {
addHandler: addHandler,
});
return chain;
return chainApi;
}

function isOfType(actionTypeOrTypes, action) {
Expand Down
2 changes: 1 addition & 1 deletion codesandbox/src/typesafe-actions/index.umd.js.map

Large diffs are not rendered by default.

76 changes: 36 additions & 40 deletions codesandbox/src/typesafe-actions/type-helpers.d.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
export interface TypeMeta<T extends StringType> {
getType?: () => T;
}
export declare type ActionCreator<T extends StringType> = (...args: any[]) => {
type: T;
export declare type TypeConstant = string;
export declare type Action<TType extends TypeConstant = TypeConstant> = {
type: TType;
};
export declare type ActionType<ActionCreatorOrMap extends any> = ActionCreatorOrMap extends ActionCreator<string> ? ReturnType<ActionCreatorOrMap> : ActionCreatorOrMap extends Record<any, any> ? {
[K in keyof ActionCreatorOrMap]: ActionType<ActionCreatorOrMap[K]>;
}[keyof ActionCreatorOrMap] : ActionCreatorOrMap extends infer R ? never : never;
export declare type StateType<ReducerOrMap> = ReducerOrMap extends (...args: any[]) => any ? ReturnType<ReducerOrMap> : ReducerOrMap extends object ? {
[K in keyof ReducerOrMap]: StateType<ReducerOrMap[K]>;
} : never;
export declare type StringType = string;
export declare type EmptyAction<T extends StringType> = {
type: T;
export declare type ActionCreator<TType extends TypeConstant> = (...args: any[]) => Action<TType>;
export declare type Reducer<TState, TAction extends Action> = (state: TState | undefined, action: TAction) => TState;
export declare type EmptyAction<TType extends TypeConstant> = {
type: TType;
};
export declare type PayloadAction<T extends StringType, P> = {
type: T;
payload: P;
export declare type PayloadAction<TType extends TypeConstant, TPayload> = {
type: TType;
payload: TPayload;
};
export declare type MetaAction<T extends StringType, M> = {
type: T;
meta: M;
export declare type MetaAction<TType extends TypeConstant, TMeta> = {
type: TType;
meta: TMeta;
};
export declare type PayloadMetaAction<T extends StringType, P, M> = {
type: T;
payload: P;
meta: M;
export declare type PayloadMetaAction<TType extends TypeConstant, TPayload, TMeta> = {
type: TType;
payload: TPayload;
meta: TMeta;
};
export interface FluxStandardAction<T extends StringType, P = undefined, M = undefined> {
type: T;
payload: P;
meta: M;
error?: true;
export declare type EmptyAC<TType extends TypeConstant> = () => EmptyAction<TType>;
export declare type PayloadAC<TType extends TypeConstant, TPayload> = (payload: TPayload) => PayloadAction<TType, TPayload>;
export declare type PayloadMetaAC<TType extends TypeConstant, TPayload, TMeta> = (payload: TPayload, meta: TMeta) => PayloadMetaAction<TType, TPayload, TMeta>;
export interface TypeMeta<TType extends TypeConstant> {
getType?: () => TType;
}
export declare type EmptyAC<T extends StringType> = () => EmptyAction<T>;
export declare type PayloadAC<T extends StringType, P> = (payload: P) => PayloadAction<T, P>;
export declare type PayloadMetaAC<T extends StringType, P, M> = (payload: P, meta: M) => PayloadMetaAction<T, P, M>;
export declare type ActionBuilderConstructor<T extends StringType, TPayload extends any = undefined, TMeta extends any = undefined> = [TMeta] extends [undefined] ? [TPayload] extends [undefined] ? unknown extends TPayload ? PayloadAC<T, TPayload> : unknown extends TMeta ? PayloadMetaAC<T, TPayload, TMeta> : EmptyAC<T> : PayloadAC<T, TPayload> : PayloadMetaAC<T, TPayload, TMeta>;
export declare type ActionBuilderMap<T extends StringType, TCustomAction extends any, TPayloadArg extends any = undefined, TMetaArg extends any = undefined> = [TMetaArg] extends [undefined] ? [TPayloadArg] extends [undefined] ? () => {
type: T;
} & TCustomAction : (payload: TPayloadArg) => {
type: T;
} & TCustomAction : (payload: TPayloadArg, meta: TMetaArg) => {
type: T;
} & TCustomAction;
export declare type ActionType<TActionCreatorOrMap extends any> = TActionCreatorOrMap extends ActionCreator<TypeConstant> ? ReturnType<TActionCreatorOrMap> : TActionCreatorOrMap extends Record<any, any> ? {
[K in keyof TActionCreatorOrMap]: ActionType<TActionCreatorOrMap[K]>;
}[keyof TActionCreatorOrMap] : TActionCreatorOrMap extends infer R ? never : never;
export declare type StateType<TReducerOrMap extends any> = TReducerOrMap extends Reducer<any, any> ? ReturnType<TReducerOrMap> : TReducerOrMap extends Record<any, any> ? {
[K in keyof TReducerOrMap]: StateType<TReducerOrMap[K]>;
} : never;
export declare type ActionBuilderConstructor<TType extends TypeConstant, TPayload extends any = undefined, TMeta extends any = undefined> = [TMeta] extends [undefined] ? [TPayload] extends [undefined] ? unknown extends TPayload ? PayloadAC<TType, TPayload> : unknown extends TMeta ? PayloadMetaAC<TType, TPayload, TMeta> : EmptyAC<TType> : PayloadAC<TType, TPayload> : PayloadMetaAC<TType, TPayload, TMeta>;
export declare type ActionBuilderMap<TType extends TypeConstant, TActionProps extends any, TPayloadArg extends any = undefined, TMetaArg extends any = undefined> = [TMetaArg] extends [undefined] ? [TPayloadArg] extends [undefined] ? () => {
type: TType;
} & TActionProps : (payload: TPayloadArg) => {
type: TType;
} & TActionProps : (payload: TPayloadArg, meta: TMetaArg) => {
type: TType;
} & TActionProps;
8 changes: 4 additions & 4 deletions codesandbox/src/typesafe-actions/utils/validation.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ActionCreator, TypeMeta, StringType } from '../type-helpers';
import { ActionCreator, TypeMeta, TypeConstant } from '../type-helpers';
export declare function checkIsEmpty(arg: unknown, argPosition?: number): boolean;
export declare function throwIsEmpty(argPosition?: number): never;
export declare function checkValidActionCreator(arg: unknown): arg is ActionCreator<StringType>;
export declare function checkValidActionCreator(arg: unknown): arg is ActionCreator<TypeConstant>;
export declare function checkInvalidActionCreator(arg: unknown): boolean;
export declare function throwInvalidActionCreator(argPosition?: number): never;
export declare function checkInvalidActionCreatorInArray(arg: ActionCreator<StringType> & TypeMeta<StringType>, idx: number): void | never;
export declare function checkInvalidActionCreatorInArray(arg: ActionCreator<TypeConstant> & TypeMeta<TypeConstant>, idx: number): void | never;
export declare function checkValidActionType(arg: unknown): arg is string | symbol;
export declare function checkInvalidActionType(arg: unknown): arg is string | symbol;
export declare function throwInvalidActionType(argPosition?: number): never;
export declare function checkInvalidActionTypeInArray(arg: StringType, idx: number): void | never;
export declare function checkInvalidActionTypeInArray(arg: TypeConstant, idx: number): void | never;
export declare function throwInvalidActionTypeOrActionCreator(argPosition?: number): never;

0 comments on commit 1fd50de

Please sign in to comment.