Skip to content

Commit

Permalink
🐛 fix(typing) add missing elements and fixes when() signature
Browse files Browse the repository at this point in the history
  • Loading branch information
AFaugeras committed Jan 30, 2020
1 parent 7721e97 commit 37cd71e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 52 deletions.
43 changes: 24 additions & 19 deletions packages/drivers/http/dist/index.d.ts
@@ -1,30 +1,35 @@
declare module '@k-ramel/driver-http' {
import { StoreBase, Driver, BaseAction } from 'k-ramel'
declare module "@k-ramel/driver-http" {
import { StoreBase, Driver, BaseAction } from "k-ramel";

const httpDriver: () => Driver
const httpDriver: () => Driver;

export type HTTPOptions = Omit<body, RequestInit>
export type RequestFunction = (url: string, body?: BodyInit | object, options?: HTTPOptions) => void
export type HTTPOptions = Omit<body, RequestInit>;
export type RequestFunction = (
url: string,
body?: BodyInit | object,
options?: HTTPOptions
) => void;

export type HTTPDriver = (
name: string,
context?: object,
context?: any
) => {
post: RequestFunction
get: RequestFunction
head: RequestFunction
patch: RequestFunction
put: RequestFunction
delete: RequestFunction
options: RequestFunction
connect: RequestFunction
}
post: RequestFunction;
get: RequestFunction;
head: RequestFunction;
patch: RequestFunction;
put: RequestFunction;
delete: RequestFunction;
options: RequestFunction;
connect: RequestFunction;
};

export interface HTTPBaseAction<Payload> extends BaseAction {
payload: Payload
status: number
headers: Headers
payload: Payload;
context: any;
status: number;
headers: Headers;
}

export default httpDriver
export default httpDriver;
}
43 changes: 24 additions & 19 deletions packages/drivers/http/typing/index.d.ts
@@ -1,30 +1,35 @@
declare module '@k-ramel/driver-http' {
import { StoreBase, Driver, BaseAction } from 'k-ramel'
declare module "@k-ramel/driver-http" {
import { StoreBase, Driver, BaseAction } from "k-ramel";

const httpDriver: () => Driver
const httpDriver: () => Driver;

export type HTTPOptions = Omit<body, RequestInit>
export type RequestFunction = (url: string, body?: BodyInit | object, options?: HTTPOptions) => void
export type HTTPOptions = Omit<body, RequestInit>;
export type RequestFunction = (
url: string,
body?: BodyInit | object,
options?: HTTPOptions
) => void;

export type HTTPDriver = (
name: string,
context?: object,
context?: any
) => {
post: RequestFunction
get: RequestFunction
head: RequestFunction
patch: RequestFunction
put: RequestFunction
delete: RequestFunction
options: RequestFunction
connect: RequestFunction
}
post: RequestFunction;
get: RequestFunction;
head: RequestFunction;
patch: RequestFunction;
put: RequestFunction;
delete: RequestFunction;
options: RequestFunction;
connect: RequestFunction;
};

export interface HTTPBaseAction<Payload> extends BaseAction {
payload: Payload
status: number
headers: Headers
payload: Payload;
context: any;
status: number;
headers: Headers;
}

export default httpDriver
export default httpDriver;
}
19 changes: 12 additions & 7 deletions packages/k-ramel/dist/index.d.ts
Expand Up @@ -49,17 +49,22 @@ declare module "k-ramel" {

export interface StoreBase extends StoreDefinitionBase {
dispatch: Dispatch;
listeners: any;
}

export type BaseAction = {
export interface BaseAction {
type: string;
};
}

export type ReactionType<
Action extends BaseAction = BaseAction,
Store = {},
Drivers = {}
> = (action: Action, store: Store, drivers: Drivers) => void;
A extends API = {},
S extends StoreDefinitionBase = {},
D = {}
> = (action: A & BaseAction, store: S & StoreBase, drivers: D) => any;

export const when = (type: string | RegExp) => (reaction: any) => {};
export const when: (
...matchers: (string | RegExp)[]
) => <A extends API, S extends StoreDefinitionBase, D>(
callback: ReactionType<A, S, D>
) => ReactionType<A, S, D>;
}
19 changes: 12 additions & 7 deletions packages/k-ramel/typing/index.d.ts
Expand Up @@ -49,17 +49,22 @@ declare module "k-ramel" {

export interface StoreBase extends StoreDefinitionBase {
dispatch: Dispatch;
listeners: any;
}

export type BaseAction = {
export interface BaseAction {
type: string;
};
}

export type ReactionType<
Action extends BaseAction = BaseAction,
Store = {},
Drivers = {}
> = (action: Action, store: Store, drivers: Drivers) => void;
A extends API = {},
S extends StoreDefinitionBase = {},
D = {}
> = (action: A & BaseAction, store: S & StoreBase, drivers: D) => any;

export const when = (type: string | RegExp) => (reaction: any) => {};
export const when: (
...matchers: (string | RegExp)[]
) => <A extends API, S extends StoreDefinitionBase, D>(
callback: ReactionType<A, S, D>
) => ReactionType<A, S, D>;
}

0 comments on commit 37cd71e

Please sign in to comment.