-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from desko27/feature/add-root-props
Add RootProps implementation and docs
- Loading branch information
Showing
5 changed files
with
116 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,47 @@ | ||
export type CallFunction<P, R> = (props: P) => Promise<R> | ||
|
||
export interface PrivateCallContext<P, R> { | ||
export interface PrivateCallContext<Props, Response> { | ||
key: string | ||
props: P | ||
end: (response: R) => void | ||
props: Props | ||
end: (response: Response) => void | ||
} | ||
export type CallContext<P, R> = Omit<PrivateCallContext<P, R>, 'props'> | ||
export type PrivateStackState<Props, Response> = PrivateCallContext< | ||
Props, | ||
Response | ||
>[] | ||
export type PrivateStackStateSetter<Props, Response> = React.Dispatch< | ||
React.SetStateAction<PrivateStackState<Props, Response>> | ||
> | ||
|
||
/** | ||
* The call() method | ||
*/ | ||
export type CallFunction<Props, Response> = (props: Props) => Promise<Response> | ||
|
||
export type PropsWithCall<P, R> = P & { call: CallContext<P, R> } | ||
export type UserComponent<P, R> = React.FunctionComponent<PropsWithCall<P, R>> | ||
/** | ||
* The special call prop in UserComponent | ||
*/ | ||
export type CallContext<Props, Response, RootProps> = Omit< | ||
PrivateCallContext<Props, Response>, | ||
'props' | ||
> & { root: RootProps } | ||
|
||
export type Callable<P, R> = { | ||
Root: React.FunctionComponent | ||
call: CallFunction<P, R> | ||
/** | ||
* User props + the call prop | ||
*/ | ||
export type PropsWithCall<Props, Response, RootProps> = Props & { | ||
call: CallContext<Props, Response, RootProps> | ||
} | ||
|
||
export type PrivateStackState<P, R> = PrivateCallContext<P, R>[] | ||
export type PrivateStackStateSetter<P, R> = React.Dispatch< | ||
React.SetStateAction<PrivateStackState<P, R>> | ||
/** | ||
* What is passed to createCallable | ||
*/ | ||
export type UserComponent<Props, Response, RootProps> = React.FunctionComponent< | ||
PropsWithCall<Props, Response, RootProps> | ||
> | ||
|
||
/** | ||
* What createCallable returns | ||
*/ | ||
export type Callable<Props, Response, RootProps> = { | ||
Root: React.FunctionComponent<RootProps> | ||
call: CallFunction<Props, Response> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters