This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Charles Stover - Vendor
committed
Nov 27, 2018
1 parent
c7327e9
commit 7bc939b
Showing
2 changed files
with
59 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as React from 'react'; | ||
|
||
interface AnyObject { | ||
[key: string]: any; | ||
} | ||
|
||
type GlobalCallback = (global: GlobalState) => void; | ||
|
||
// TypeScript does not allow props P to be passed to static methods. | ||
declare class GlobalComponent<P = {}, S = {}> extends React.Component<P, S> { | ||
static getDerivedGlobalFromProps?: (props: AnyObject, prevGloba: GlobalState, prevState: AnyObject) => NewGlobal; | ||
private _globalCallback: () => void; | ||
readonly global: Readonly<GlobalState>; | ||
setGlobal(newGlobal: NewGlobal, callback?: GlobalCallback): Promise<void> | void; | ||
} | ||
|
||
declare class GlobalPureComponent<P = {}, S = {}> extends React.PureComponent<P, S> { | ||
static getDerivedGlobalFromProps?: (props: AnyObject, prevGloba: GlobalState, prevState: AnyObject) => NewGlobal; | ||
private _globalCallback: () => void; | ||
readonly global: Readonly<GlobalState>; | ||
setGlobal(newGlobal: NewGlobal, callback?: GlobalCallback): Promise<void> | void; | ||
} | ||
|
||
type GlobalReducer = (state: GlobalState, ...args: any[]) => NewGlobal; | ||
|
||
type GlobalPropertySetter = (value: any) => void; | ||
|
||
interface GlobalState { | ||
[key: string]: any; | ||
} | ||
|
||
type GlobalStateSetter = (newGlobal: NewGlobal, callback?: GlobalCallback) => Promise<void> | void; | ||
|
||
type LocalReducer = (...args: any[]) => void; | ||
|
||
type MapGlobalToProps<ComponentProps, NewProps> = (global: GlobalState, props: ComponentProps) => NewProps; | ||
|
||
type NewGlobal = NewGlobalFunction | null | Partial<GlobalState> | Promise<NewGlobalFunction> | Promise<null> | Promise<Partial<GlobalState>>; | ||
|
||
type NewGlobalFunction = (global: GlobalState) => NewGlobal; | ||
|
||
interface ReactN extends React { | ||
(Component: React.ComponentType): GlobalComponent; | ||
addReducer(name: string, reducer: GlobalReducer): void; | ||
Component: GlobalComponent; | ||
default: ReactN; | ||
PureComponent: GlobalPureComponent; | ||
resetGlobal(): void; | ||
setGlobal(newGlobal: NewGlobal, callback?: GlobalCallback): Promise<void> | void; | ||
useGlobal(): [ GlobalState, GlobalStateSetter ]; | ||
useGlobal<T>(property: keyof GlobalState, setterOnly?: boolean): [ T, GlobalPropertySetter ]; | ||
useGlobal(reducer: GlobalReducer): LocalReducer; | ||
withGlobal<CP, NP>(getGlobal: MapGlobalToProps<CP, NP>): (Component: React.ComponentType<CP & NP>) => GlobalPureComponent<CP, never>; | ||
} | ||
|
||
declare const _: ReactN; | ||
export = _; | ||
export as namespace ReactN; |
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