From 0786c73ba9eceb142152ae607be4e024fcd0765d Mon Sep 17 00:00:00 2001 From: Paul Blair Date: Thu, 9 Jun 2016 13:17:56 -0400 Subject: [PATCH 1/7] Fable bindings for Redux along with react-redux and react-router-redux. --- import/react-redux/Fable.Import.ReactRedux.fs | 41 +++++++++++++ import/react-redux/README.md | 31 ++++++++++ import/react-redux/package.json | 13 ++++ .../Fable.Import.ReactRouterRedux.fs | 61 +++++++++++++++++++ import/react-router-redux/README.md | 31 ++++++++++ import/react-router-redux/package.json | 13 ++++ import/redux/Fable.Import.Redux.fs | 46 ++++++++++++++ import/redux/README.md | 31 ++++++++++ import/redux/package.json | 13 ++++ 9 files changed, 280 insertions(+) create mode 100644 import/react-redux/Fable.Import.ReactRedux.fs create mode 100644 import/react-redux/README.md create mode 100644 import/react-redux/package.json create mode 100644 import/react-router-redux/Fable.Import.ReactRouterRedux.fs create mode 100644 import/react-router-redux/README.md create mode 100644 import/react-router-redux/package.json create mode 100644 import/redux/Fable.Import.Redux.fs create mode 100644 import/redux/README.md create mode 100644 import/redux/package.json diff --git a/import/react-redux/Fable.Import.ReactRedux.fs b/import/react-redux/Fable.Import.ReactRedux.fs new file mode 100644 index 0000000000..13c1b8a691 --- /dev/null +++ b/import/react-redux/Fable.Import.ReactRedux.fs @@ -0,0 +1,41 @@ +namespace Fable.Import +open System +open System.Text.RegularExpressions +open Fable.Core +open Fable.Import.JS + +module ``react-redux`` = + type [] ElementClass() = + interface Component + + + and ClassDecorator = + [] abstract Invoke: ``component``: 'T -> 'T + + and MapStateToProps = + [] abstract Invoke: state: obj * ?ownProps: obj -> obj + + and MapDispatchToPropsFunction = + [] abstract Invoke: dispatch: Dispatch * ?ownProps: obj -> obj + + and MapDispatchToPropsObject = + [] abstract Item: name: string -> ActionCreator with get, set + + and MergeProps = + [] abstract Invoke: stateProps: obj * dispatchProps: obj * ownProps: obj -> obj + + and Options = + abstract ``pure``: bool with get, set + + and Property = + abstract store: Store option with get, set + abstract children: Function option with get, set + + and [] Provider() = + interface Component + + + type [] Globals = + static member connect(?mapStateToProps: MapStateToProps, ?mapDispatchToProps: U2, ?mergeProps: MergeProps, ?options: Options): ClassDecorator = failwith "JS only" + + diff --git a/import/react-redux/README.md b/import/react-redux/README.md new file mode 100644 index 0000000000..7acdb104de --- /dev/null +++ b/import/react-redux/README.md @@ -0,0 +1,31 @@ +# fable-import-react-redux + +Fable bindings for the Redux React bindings + +## Installation + +```sh +$ npm install --save react-redux fable-core +$ npm install --save-dev fable-import-react-redux +``` + +## Usage + +### In a F# project (.fsproj) + +```xml + + + + +``` + +### In a F# script (.fsx) + +```fsharp +#r "node_modules/fable-core/Fable.Core.dll" +#load "node_modules/fable-import-react-redux/Fable.Import.ReactRedux.fs" + +open Fable.Core +open Fable.Import +``` diff --git a/import/react-redux/package.json b/import/react-redux/package.json new file mode 100644 index 0000000000..c9c8e25a85 --- /dev/null +++ b/import/react-redux/package.json @@ -0,0 +1,13 @@ +{ + "name": "fable-import-react-redux", + "version": "0.0.1", + "description": "Fable bindings for Redux bindings for React", + "repository": { + "type": "git", + "url": "https://github.com/fsprojects/Fable/import/react-redux" + }, + "license": "Apache-2.0", + "author": "Paul Blair", + "keywords": [ "fable", "fable-compiler", "fsharp", "F#", "React", "Redux" ], + "homepage": "https://github.com/fsprojects/Fable#readme" +} diff --git a/import/react-router-redux/Fable.Import.ReactRouterRedux.fs b/import/react-router-redux/Fable.Import.ReactRouterRedux.fs new file mode 100644 index 0000000000..54d1883c33 --- /dev/null +++ b/import/react-router-redux/Fable.Import.ReactRouterRedux.fs @@ -0,0 +1,61 @@ +namespace Fable.Import +open System +open System.Text.RegularExpressions +open Fable.Core +open Fable.Import.JS + +module ReactRouterRedux = + type LocationDescriptor = + U2 + + and PushAction = + Func + + and ReplaceAction = + Func + + and GoAction = + Func + + and GoForwardAction = + Func + + and GoBackAction = + Func + + and RouterAction = + obj + + and RouteActions = + abstract push: PushAction with get, set + abstract replace: ReplaceAction with get, set + abstract go: GoAction with get, set + abstract goForward: GoForwardAction with get, set + abstract goBack: GoBackAction with get, set + + and ReactRouterReduxHistory = + inherit H.History + abstract unsubscribe: unit -> unit + + and DefaultSelectLocationState = + inherit Function + [] abstract Invoke: state: obj -> obj + + and SyncHistoryWithStoreOptions = + abstract selectLocationState: DefaultSelectLocationState option with get, set + abstract adjustUrlOnReplay: bool option with get, set + + type [] Globals = + static member CALL_HISTORY_METHOD with get(): string = failwith "JS only" and set(v: string): unit = failwith "JS only" + static member LOCATION_CHANGE with get(): string = failwith "JS only" and set(v: string): unit = failwith "JS only" + static member push with get(): PushAction = failwith "JS only" and set(v: PushAction): unit = failwith "JS only" + static member replace with get(): ReplaceAction = failwith "JS only" and set(v: ReplaceAction): unit = failwith "JS only" + static member go with get(): GoAction = failwith "JS only" and set(v: GoAction): unit = failwith "JS only" + static member goBack with get(): GoForwardAction = failwith "JS only" and set(v: GoForwardAction): unit = failwith "JS only" + static member goForward with get(): GoBackAction = failwith "JS only" and set(v: GoBackAction): unit = failwith "JS only" + static member routerActions with get(): RouteActions = failwith "JS only" and set(v: RouteActions): unit = failwith "JS only" + static member routerReducer(?state: obj, ?options: obj): R.Reducer = failwith "JS only" + static member syncHistoryWithStore(history: H.History, store: R.Store, ?options: SyncHistoryWithStoreOptions): ReactRouterReduxHistory = failwith "JS only" + static member routerMiddleware(history: H.History): R.Middleware = failwith "JS only" + + diff --git a/import/react-router-redux/README.md b/import/react-router-redux/README.md new file mode 100644 index 0000000000..3d55041806 --- /dev/null +++ b/import/react-router-redux/README.md @@ -0,0 +1,31 @@ +# fable-import-react-router-redux + +Fable bindings for the Redux React Router (react-router-redux) bindings. + +## Installation + +```sh +$ npm install --save react-router-redux fable-core +$ npm install --save-dev fable-import-react-router-redux +``` + +## Usage + +### In a F# project (.fsproj) + +```xml + + + + +``` + +### In a F# script (.fsx) + +```fsharp +#r "node_modules/fable-core/Fable.Core.dll" +#load "node_modules/fable-import-react-router-redux/Fable.Import.ReactRouterRedux.fs" + +open Fable.Core +open Fable.Import +``` diff --git a/import/react-router-redux/package.json b/import/react-router-redux/package.json new file mode 100644 index 0000000000..fb96b4ccf5 --- /dev/null +++ b/import/react-router-redux/package.json @@ -0,0 +1,13 @@ +{ + "name": "fable-import-react-router-redux", + "version": "0.0.1", + "description": "Fable bindings for Redux bindings for React Router", + "repository": { + "type": "git", + "url": "https://github.com/fsprojects/Fable/import/react-router-redux" + }, + "license": "Apache-2.0", + "author": "Paul Blair", + "keywords": [ "fable", "fable-compiler", "fsharp", "F#", "React", "Redux" ], + "homepage": "https://github.com/fsprojects/Fable#readme" +} diff --git a/import/redux/Fable.Import.Redux.fs b/import/redux/Fable.Import.Redux.fs new file mode 100644 index 0000000000..d7f3cb019c --- /dev/null +++ b/import/redux/Fable.Import.Redux.fs @@ -0,0 +1,46 @@ +namespace Fable.Import +open System +open System.Text.RegularExpressions +open Fable.Core +open Fable.Import.JS + +module Redux = + type ActionCreator = + inherit Function + [] abstract Invoke: [] args: obj[] -> obj + + and Reducer = + inherit Function + [] abstract Invoke: state: obj * action: obj -> obj + + and Dispatch = + inherit Function + [] abstract Invoke: action: obj -> obj + + and StoreMethods = + abstract dispatch: Dispatch with get, set + abstract getState: unit -> obj + + and MiddlewareArg = + abstract dispatch: Dispatch with get, set + abstract getState: Function with get, set + + and Middleware = + inherit Function + [] abstract Invoke: obj: MiddlewareArg -> Function + + and [] Store() = + member __.getReducer(): Reducer = failwith "JS only" + member __.replaceReducer(nextReducer: Reducer): unit = failwith "JS only" + member __.dispatch(action: obj): obj = failwith "JS only" + member __.getState(): obj = failwith "JS only" + member __.subscribe(listener: Function): Function = failwith "JS only" + + type [] Globals = + static member createStore(reducer: Reducer, ?initialState: obj, ?enhancer: Function): Store = failwith "JS only" + static member bindActionCreators(actionCreators: 'T, dispatch: Dispatch): 'T = failwith "JS only" + static member combineReducers(reducers: obj): Reducer = failwith "JS only" + static member applyMiddleware([] middlewares: Middleware[]): Function = failwith "JS only" + static member compose([] functions: Function[]): 'T = failwith "JS only" + + diff --git a/import/redux/README.md b/import/redux/README.md new file mode 100644 index 0000000000..05b0d5ee82 --- /dev/null +++ b/import/redux/README.md @@ -0,0 +1,31 @@ +# fable-import-redux + +Fable bindings for Redux + +## Installation + +```sh +$ npm install --save redux fable-core +$ npm install --save-dev fable-import-redux +``` + +## Usage + +### In a F# project (.fsproj) + +```xml + + + + +``` + +### In a F# script (.fsx) + +```fsharp +#r "node_modules/fable-core/Fable.Core.dll" +#load "node_modules/fable-import-redux/Fable.Import.Redux.fs" + +open Fable.Core +open Fable.Import +``` diff --git a/import/redux/package.json b/import/redux/package.json new file mode 100644 index 0000000000..e4697b96a1 --- /dev/null +++ b/import/redux/package.json @@ -0,0 +1,13 @@ +{ + "name": "fable-import-redux", + "version": "0.0.1", + "description": "Fable bindings for Redux", + "repository": { + "type": "git", + "url": "https://github.com/fsprojects/Fable/import/redux" + }, + "license": "Apache-2.0", + "author": "Paul Blair", + "keywords": [ "fable", "fable-compiler", "fsharp", "F#", "Redux" ], + "homepage": "https://github.com/fsprojects/Fable#readme" +} From 821ecccd6900e808d470a3a1494ecb3492a7610a Mon Sep 17 00:00:00 2001 From: Paul Blair Date: Thu, 9 Jun 2016 14:30:31 -0400 Subject: [PATCH 2/7] Fix module name. --- import/react-redux/Fable.Import.ReactRedux.fs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/import/react-redux/Fable.Import.ReactRedux.fs b/import/react-redux/Fable.Import.ReactRedux.fs index 13c1b8a691..6fd49f1e20 100644 --- a/import/react-redux/Fable.Import.ReactRedux.fs +++ b/import/react-redux/Fable.Import.ReactRedux.fs @@ -4,7 +4,7 @@ open System.Text.RegularExpressions open Fable.Core open Fable.Import.JS -module ``react-redux`` = +module ReactRedux = type [] ElementClass() = interface Component @@ -37,5 +37,3 @@ module ``react-redux`` = type [] Globals = static member connect(?mapStateToProps: MapStateToProps, ?mapDispatchToProps: U2, ?mergeProps: MergeProps, ?options: Options): ClassDecorator = failwith "JS only" - - From b6b8e8afb57b7e83e9878601efe14361961d38a0 Mon Sep 17 00:00:00 2001 From: Paul Blair Date: Thu, 9 Jun 2016 22:21:47 -0400 Subject: [PATCH 3/7] Add react-router, which was inadvertently omitted; fix Redux and related modules interface definitions; include original Typescript files from which the interfaces were generated; improve documentation and include version numbering. --- import/Fable.Import.Test.fsproj | 5 + import/react-redux/Fable.Import.ReactRedux.fs | 19 +- import/react-redux/README.md | 5 +- import/react-redux/package.json | 2 +- import/react-redux/react-redux.d.ts | 103 ++++ .../Fable.Import.ReactRouterRedux.fs | 19 +- import/react-router-redux/README.md | 4 +- import/react-router-redux/package.json | 2 +- .../react-router-redux.d.ts | 62 +++ .../Fable.Import.HistoryModule.fs | 168 ++++++ .../react-router/Fable.Import.ReactRouter.fs | 301 ++++++++++ import/react-router/README.md | 36 ++ import/react-router/history.d.ts | 236 ++++++++ import/react-router/package.json | 13 + import/react-router/react-router.d.ts | 513 ++++++++++++++++++ import/redux/Fable.Import.Redux.fs | 19 +- import/redux/README.md | 5 +- import/redux/package.json | 2 +- import/redux/redux.d.ts | 52 ++ 19 files changed, 1534 insertions(+), 32 deletions(-) create mode 100644 import/react-redux/react-redux.d.ts create mode 100644 import/react-router-redux/react-router-redux.d.ts create mode 100644 import/react-router/Fable.Import.HistoryModule.fs create mode 100644 import/react-router/Fable.Import.ReactRouter.fs create mode 100644 import/react-router/README.md create mode 100644 import/react-router/history.d.ts create mode 100644 import/react-router/package.json create mode 100644 import/react-router/react-router.d.ts create mode 100644 import/redux/redux.d.ts diff --git a/import/Fable.Import.Test.fsproj b/import/Fable.Import.Test.fsproj index 81c2cf629f..4bf47111f9 100644 --- a/import/Fable.Import.Test.fsproj +++ b/import/Fable.Import.Test.fsproj @@ -49,6 +49,11 @@ + + + + + diff --git a/import/react-redux/Fable.Import.ReactRedux.fs b/import/react-redux/Fable.Import.ReactRedux.fs index 6fd49f1e20..75eaac85db 100644 --- a/import/react-redux/Fable.Import.ReactRedux.fs +++ b/import/react-redux/Fable.Import.ReactRedux.fs @@ -3,10 +3,13 @@ open System open System.Text.RegularExpressions open Fable.Core open Fable.Import.JS +open Fable.Import.React +open Fable.Import.Redux +// Type definitions for react-redux v. 4.4.0, generated from Typescript module ReactRedux = - type [] ElementClass() = - interface Component + type [] ElementClass<'P, 'S>(?props: 'P, ?context: obj) = + inherit Component<'P, 'S>(?props = props, ?context = context) and ClassDecorator = @@ -19,20 +22,20 @@ module ReactRedux = [] abstract Invoke: dispatch: Dispatch * ?ownProps: obj -> obj and MapDispatchToPropsObject = - [] abstract Item: name: string -> ActionCreator with get, set + [] abstract Item: name: string -> ActionCreator with get and MergeProps = [] abstract Invoke: stateProps: obj * dispatchProps: obj * ownProps: obj -> obj and Options = - abstract ``pure``: bool with get, set + abstract ``pure``: bool with get and Property = - abstract store: Store option with get, set - abstract children: Function option with get, set + abstract store: Store option with get + abstract children: Function option with get - and [] Provider() = - interface Component + and [] Provider(?props: Property, ?context: obj) = + inherit Component(?props = props, ?context = context) type [] Globals = diff --git a/import/react-redux/README.md b/import/react-redux/README.md index 7acdb104de..4d93fe3829 100644 --- a/import/react-redux/README.md +++ b/import/react-redux/README.md @@ -1,6 +1,9 @@ # fable-import-react-redux -Fable bindings for the Redux React bindings +Fable bindings for the Redux React bindings (react-redux) version 4.4.0. +These were generated from the Typescript file but modified to remove setters. +In addition, ElementClass needs to inherit from Component rather than +trying to implement it as an interface. ## Installation diff --git a/import/react-redux/package.json b/import/react-redux/package.json index c9c8e25a85..b78d210952 100644 --- a/import/react-redux/package.json +++ b/import/react-redux/package.json @@ -1,7 +1,7 @@ { "name": "fable-import-react-redux", "version": "0.0.1", - "description": "Fable bindings for Redux bindings for React", + "description": "Fable bindings for Redux bindings for React (react-redux) version 4.4.0", "repository": { "type": "git", "url": "https://github.com/fsprojects/Fable/import/react-redux" diff --git a/import/react-redux/react-redux.d.ts b/import/react-redux/react-redux.d.ts new file mode 100644 index 0000000000..6f05a17b6e --- /dev/null +++ b/import/react-redux/react-redux.d.ts @@ -0,0 +1,103 @@ +// Type definitions for react-redux 4.4.0 +// Project: https://github.com/rackt/react-redux +// Definitions by: Qubo , Sean Kelley +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// + +declare module "react-redux" { + import { ComponentClass, Component, StatelessComponent, ReactNode } from 'react'; + import { Store, Dispatch, ActionCreator } from 'redux'; + + interface ComponentDecorator { + (component: ComponentClass|StatelessComponent): ComponentClass; + } + + /** + * Decorator that infers the type from the original component + * + * Can't use the above decorator because it would default the type to {} + */ + export interface InferableComponentDecorator { + |StatelessComponent

)>(component: TComponentConstruct): TComponentConstruct; + } + + /** + * Connects a React component to a Redux store. + * + * - Without arguments, just wraps the component, without changing the behavior / props + * + * - If 2 params are passed (3rd param, mergeProps, is skipped), default behavior + * is to override ownProps (as stated in the docs), so what remains is everything that's + * not a state or dispatch prop + * + * - When 3rd param is passed, we don't know if ownProps propagate and whether they + * should be valid component props, because it depends on mergeProps implementation. + * As such, it is the user's responsibility to extend ownProps interface from state or + * dispatch props or both when applicable + * + * @param mapStateToProps + * @param mapDispatchToProps + * @param mergeProps + * @param options + */ + export function connect(): InferableComponentDecorator; + + export function connect( + mapStateToProps: MapStateToProps, + mapDispatchToProps?: MapDispatchToPropsFunction|MapDispatchToPropsObject + ): ComponentDecorator; + + export function connect( + mapStateToProps: MapStateToProps, + mapDispatchToProps: MapDispatchToPropsFunction|MapDispatchToPropsObject, + mergeProps: MergeProps, + options?: Options + ): ComponentDecorator; + + interface MapStateToProps { + (state: any, ownProps?: TOwnProps): TStateProps; + } + + interface MapDispatchToPropsFunction { + (dispatch: Dispatch, ownProps?: TOwnProps): TDispatchProps; + } + + interface MapDispatchToPropsObject { + [name: string]: ActionCreator; + } + + interface MergeProps { + (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps): TStateProps & TDispatchProps; + } + + interface Options { + /** + * If true, implements shouldComponentUpdate and shallowly compares the result of mergeProps, + * preventing unnecessary updates, assuming that the component is a “pure” component + * and does not rely on any input or state other than its props and the selected Redux store’s state. + * Defaults to true. + * @default true + */ + pure?: boolean; + /** + * If true, stores a ref to the wrapped component instance and makes it available via + * getWrappedInstance() method. Defaults to false. + */ + withRef?: boolean; + } + + export interface ProviderProps { + /** + * The single Redux store in your application. + */ + store?: Store; + children?: ReactNode; + } + + /** + * Makes the Redux store available to the connect() calls in the component hierarchy below. + */ + export class Provider extends Component { } +} diff --git a/import/react-router-redux/Fable.Import.ReactRouterRedux.fs b/import/react-router-redux/Fable.Import.ReactRouterRedux.fs index 54d1883c33..bbef340d84 100644 --- a/import/react-router-redux/Fable.Import.ReactRouterRedux.fs +++ b/import/react-router-redux/Fable.Import.ReactRouterRedux.fs @@ -3,7 +3,10 @@ open System open System.Text.RegularExpressions open Fable.Core open Fable.Import.JS +module H = Fable.Import.HistoryModule +module R = Fable.Import.Redux +// Type definitions for react-router-redux v4.0.0, generated from Typescript module ReactRouterRedux = type LocationDescriptor = U2 @@ -27,11 +30,11 @@ module ReactRouterRedux = obj and RouteActions = - abstract push: PushAction with get, set - abstract replace: ReplaceAction with get, set - abstract go: GoAction with get, set - abstract goForward: GoForwardAction with get, set - abstract goBack: GoBackAction with get, set + abstract push: PushAction with get + abstract replace: ReplaceAction with get + abstract go: GoAction with get + abstract goForward: GoForwardAction with get + abstract goBack: GoBackAction with get and ReactRouterReduxHistory = inherit H.History @@ -42,8 +45,8 @@ module ReactRouterRedux = [] abstract Invoke: state: obj -> obj and SyncHistoryWithStoreOptions = - abstract selectLocationState: DefaultSelectLocationState option with get, set - abstract adjustUrlOnReplay: bool option with get, set + abstract selectLocationState: DefaultSelectLocationState option with get + abstract adjustUrlOnReplay: bool option with get type [] Globals = static member CALL_HISTORY_METHOD with get(): string = failwith "JS only" and set(v: string): unit = failwith "JS only" @@ -54,7 +57,7 @@ module ReactRouterRedux = static member goBack with get(): GoForwardAction = failwith "JS only" and set(v: GoForwardAction): unit = failwith "JS only" static member goForward with get(): GoBackAction = failwith "JS only" and set(v: GoBackAction): unit = failwith "JS only" static member routerActions with get(): RouteActions = failwith "JS only" and set(v: RouteActions): unit = failwith "JS only" - static member routerReducer(?state: obj, ?options: obj): R.Reducer = failwith "JS only" + static member routerReducer(?state: obj, ?options: obj): R.Reducer<'T,'U> = failwith "JS only" static member syncHistoryWithStore(history: H.History, store: R.Store, ?options: SyncHistoryWithStoreOptions): ReactRouterReduxHistory = failwith "JS only" static member routerMiddleware(history: H.History): R.Middleware = failwith "JS only" diff --git a/import/react-router-redux/README.md b/import/react-router-redux/README.md index 3d55041806..8c197a0ce6 100644 --- a/import/react-router-redux/README.md +++ b/import/react-router-redux/README.md @@ -1,6 +1,8 @@ # fable-import-react-router-redux -Fable bindings for the Redux React Router (react-router-redux) bindings. +Fable bindings for the Redux React Router (react-router-redux) bindings, v4.0.0. +These were generated from Typescript, with some modifications: namely, all +setters were removed, and type parameters were provided when `Reducer` is used. ## Installation diff --git a/import/react-router-redux/package.json b/import/react-router-redux/package.json index fb96b4ccf5..8bc6ca3ba8 100644 --- a/import/react-router-redux/package.json +++ b/import/react-router-redux/package.json @@ -1,7 +1,7 @@ { "name": "fable-import-react-router-redux", "version": "0.0.1", - "description": "Fable bindings for Redux bindings for React Router", + "description": "Fable bindings for Redux bindings for React Router (react-router-redux) v4.0.0", "repository": { "type": "git", "url": "https://github.com/fsprojects/Fable/import/react-router-redux" diff --git a/import/react-router-redux/react-router-redux.d.ts b/import/react-router-redux/react-router-redux.d.ts new file mode 100644 index 0000000000..b2c993132a --- /dev/null +++ b/import/react-router-redux/react-router-redux.d.ts @@ -0,0 +1,62 @@ +// Type definitions for react-router-redux v4.0.0 +// Project: https://github.com/rackt/react-router-redux +// Definitions by: Isman Usoh , Noah Shipley , Dimitri Rosenberg +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// + +declare namespace ReactRouterRedux { + import R = Redux; + import H = HistoryModule; + + const CALL_HISTORY_METHOD: string; + const LOCATION_CHANGE: string; + + const push: PushAction; + const replace: ReplaceAction; + const go: GoAction; + const goBack: GoForwardAction; + const goForward: GoBackAction; + const routerActions: RouteActions; + + type LocationDescriptor = H.Location | H.Path; + type PushAction = (nextLocation: LocationDescriptor) => RouterAction; + type ReplaceAction = (nextLocation: LocationDescriptor) => RouterAction; + type GoAction = (n: number) => RouterAction; + type GoForwardAction = () => RouterAction; + type GoBackAction = () => RouterAction; + + type RouterAction = { + type: string + payload?: any + } + + interface RouteActions { + push: PushAction; + replace: ReplaceAction; + go: GoAction; + goForward: GoForwardAction; + goBack: GoBackAction; + } + interface ReactRouterReduxHistory extends H.History { + unsubscribe(): void; + } + + interface DefaultSelectLocationState extends Function { + (state: any): any; + } + + interface SyncHistoryWithStoreOptions { + selectLocationState?: DefaultSelectLocationState; + adjustUrlOnReplay?: boolean; + } + + function routerReducer(state?: any, options?: any): R.Reducer; + function syncHistoryWithStore(history: H.History, store: R.Store, options?: SyncHistoryWithStoreOptions): ReactRouterReduxHistory; + function routerMiddleware(history: H.History): R.Middleware; +} + +declare module "react-router-redux" { + export = ReactRouterRedux; +} diff --git a/import/react-router/Fable.Import.HistoryModule.fs b/import/react-router/Fable.Import.HistoryModule.fs new file mode 100644 index 0000000000..06a5427801 --- /dev/null +++ b/import/react-router/Fable.Import.HistoryModule.fs @@ -0,0 +1,168 @@ +namespace Fable.Import +open System +open System.Text.RegularExpressions +open Fable.Core +open Fable.Import.JS +open Fable.Import.Browser + +// Type definitions for history v2.0.0; generated from Typescript with some modifications including some module names. +module HistoryModule = + type Action = + string + + and BeforeUnloadHook = + Func> + + and CreateHistory<'T> = + Func + + and CreateHistoryEnhancer<'T, 'E> = + Func, CreateHistory<'E>> + + and History = + abstract listenBefore: hook: TransitionHook -> Func + abstract listen: listener: LocationListener -> Func + abstract transitionTo: location: Location -> unit + abstract push: path: LocationDescriptor -> unit + abstract replace: path: LocationDescriptor -> unit + abstract go: n: float -> unit + abstract goBack: unit -> unit + abstract goForward: unit -> unit + abstract createKey: unit -> LocationKey + abstract createPath: path: LocationDescriptor -> Path + abstract createHref: path: LocationDescriptor -> Href + abstract createLocation: ?path: LocationDescriptor * ?action: Action * ?key: LocationKey -> Location + abstract createLocation: ?path: Path * ?state: LocationState * ?action: Action * ?key: LocationKey -> Location + abstract pushState: state: LocationState * path: Path -> unit + abstract replaceState: state: LocationState * path: Path -> unit + abstract setState: state: LocationState -> unit + abstract registerTransitionHook: hook: TransitionHook -> unit + abstract unregisterTransitionHook: hook: TransitionHook -> unit + + and HistoryOptions = + obj + + and Href = + string + + and Location = + obj + + and LocationDescriptorObject = + obj + + and LocationDescriptor = + U2 + + and LocationKey = + string + + and LocationListener = + Func + + and LocationState = + obj + + and Path = + string + + and Pathname = + string + + and Query = + obj + + and QueryString = + string + + and Search = + string + + and TransitionHook = + Func, obj> + + and Hash = + string + + and HistoryBeforeUnload = + abstract listenBeforeUnload: hook: BeforeUnloadHook -> Func + + and HistoryQueries = + abstract pushState: state: LocationState * pathname: U2 * ?query: Query -> unit + abstract replaceState: state: LocationState * pathname: U2 * ?query: Query -> unit + abstract createPath: path: Path * ?query: Query -> Path + abstract createHref: path: Path * ?query: Query -> Href + + and Module = + abstract createHistory: CreateHistory with get + abstract createHashHistory: CreateHistory with get + abstract createMemoryHistory: CreateHistory with get + abstract actions: obj with get + abstract createLocation: ?path: Path * ?state: LocationState * ?action: Action * ?key: LocationKey -> Location + abstract useBasename: createHistory: CreateHistory<'T> -> CreateHistory<'T> + abstract useBeforeUnload: createHistory: CreateHistory<'T> -> CreateHistory + abstract useQueries: createHistory: CreateHistory<'T> -> CreateHistory + + + +module CreateBrowserHistory = + type [] Globals = + static member createBrowserHistory(?options: HistoryModule.HistoryOptions): HistoryModule.History = failwith "JS only" + + + +module CreateHashHistory = + type [] Globals = + static member createHashHistory(?options: HistoryModule.HistoryOptions): HistoryModule.History = failwith "JS only" + + + +module CreateMemoryHistory = + type [] Globals = + static member createMemoryHistory(?options: HistoryModule.HistoryOptions): HistoryModule.History = failwith "JS only" + + + +module CreateLocation = + type [] Globals = + static member createLocation(?path: HistoryModule.Path, ?state: HistoryModule.LocationState, ?action: HistoryModule.Action, ?key: HistoryModule.LocationKey): HistoryModule.Location = failwith "JS only" + + + +module UseBasename = + type [] Globals = + static member useBasename(createHistory: HistoryModule.CreateHistory<'T>): HistoryModule.CreateHistory<'T> = failwith "JS only" + + + +module UseBeforeUnload = + type [] Globals = + static member useBeforeUnload(createHistory: HistoryModule.CreateHistory<'T>): HistoryModule.CreateHistory = failwith "JS only" + + + +module UseQueries = + type [] Globals = + static member useQueries(createHistory: HistoryModule.CreateHistory<'T>): HistoryModule.CreateHistory = failwith "JS only" + + + +module HistoryActions = + type [] Globals = + static member PUSH with get(): string = failwith "JS only" and set(v: string): unit = failwith "JS only" + static member REPLACE with get(): string = failwith "JS only" and set(v: string): unit = failwith "JS only" + static member POP with get(): string = failwith "JS only" and set(v: string): unit = failwith "JS only" + + + +module HistoryDOMUtils = + type [] Globals = + static member addEventListener(node: EventTarget, ``event``: string, listener: EventListenerOrEventListenerObject): unit = failwith "JS only" + static member removeEventListener(node: EventTarget, ``event``: string, listener: EventListenerOrEventListenerObject): unit = failwith "JS only" + static member getHashPath(): string = failwith "JS only" + static member replaceHashPath(path: string): unit = failwith "JS only" + static member getWindowPath(): string = failwith "JS only" + static member go(n: float): unit = failwith "JS only" + static member getUserConfirmation(message: string, callback: Func): unit = failwith "JS only" + static member supportsHistory(): bool = failwith "JS only" + static member supportsGoWithoutReloadUsingHash(): bool = failwith "JS only" diff --git a/import/react-router/Fable.Import.ReactRouter.fs b/import/react-router/Fable.Import.ReactRouter.fs new file mode 100644 index 0000000000..5163edab9d --- /dev/null +++ b/import/react-router/Fable.Import.ReactRouter.fs @@ -0,0 +1,301 @@ +namespace Fable.Import +open System +open System.Text.RegularExpressions +open Fable.Core +open Fable.Import.JS +open Fable.Import.React +module H = Fable.Import.HistoryModule + +// Type definitions for react-router v2.0.0; generated from Typescript with some modifications. +module ReactRouter = + type Component = + React.ReactType + + and EnterHook = + Func + + and LeaveHook = + Func + + and ChangeHook = + Func + + and Params = + obj + + and ParseQueryString = + Func + + and RedirectFunction = + [] abstract Invoke: location: H.LocationDescriptor -> unit + [] abstract Invoke: state: H.LocationState * pathname: U2 * ?query: H.Query -> unit + + and RouteComponent = + Component + + and RouteComponentProps<'P, 'R> = + abstract history: History option with get + abstract location: H.Location option with get + abstract ``params``: 'P option with get + abstract route: PlainRoute option with get + abstract routeParams: 'R option with get + abstract routes: ResizeArray option with get + abstract children: React.ReactElement option with get + + and RouteComponents = + obj + + and RouteConfig = + U3> + + and RouteHook = + Func + + and RoutePattern = + string + + and StringifyQuery = + Func + + and RouterListener = + Func + + and RouterState = + abstract location: H.Location with get + abstract routes: ResizeArray with get + abstract ``params``: Params with get + abstract components: ResizeArray with get + + and HistoryBase = + inherit H.History + abstract routes: ResizeArray with get + abstract parseQueryString: ParseQueryString option with get + abstract stringifyQuery: StringifyQuery option with get + + and History = + obj + + and RouterProps = + inherit React.Props + abstract history: H.History option with get + abstract routes: RouteConfig option with get + abstract createElement: Func option with get + abstract onError: Func option with get + abstract onUpdate: Func option with get + abstract parseQueryString: ParseQueryString option with get + abstract stringifyQuery: StringifyQuery option with get + + and Router = + inherit React.ComponentClass + + + and RouterElement = + inherit React.ReactElement + + + and LinkProps = + inherit React.HTMLAttributes + inherit React.Props + abstract activeStyle: React.CSSProperties option with get + abstract activeClassName: string option with get + abstract onlyActiveOnIndex: bool option with get + abstract ``to``: U2 with get + abstract query: H.Query option with get + abstract state: H.LocationState option with get + + and Link = + inherit React.ComponentClass + + + and LinkElement = + inherit React.ReactElement + + + and RouterContextProps = + inherit React.Props + abstract history: H.History option with get + abstract router: Router with get + abstract createElement: Func with get + abstract location: H.Location with get + abstract routes: RouteConfig with get + abstract ``params``: Params with get + abstract components: ResizeArray option with get + + and RouterContext = + inherit React.ComponentClass + + + and RouterContextElement = + inherit React.ReactElement + abstract history: H.History option with get + abstract location: H.Location with get + abstract router: Router option with get + + and RouteProps = + inherit React.Props + abstract path: RoutePattern option with get + abstract ``component``: RouteComponent option with get + abstract components: RouteComponents option with get + abstract getComponent: Func, unit> option with get + abstract getComponents: Func, unit> option with get + abstract onEnter: EnterHook option with get + abstract onLeave: LeaveHook option with get + abstract onChange: ChangeHook option with get + abstract getIndexRoute: Func, unit> option with get + abstract getChildRoutes: Func, unit> option with get + + and Route = + inherit React.ComponentClass + + + and RouteElement = + inherit React.ReactElement + + + and PlainRoute = + abstract path: RoutePattern option with get + abstract ``component``: RouteComponent option with get + abstract components: RouteComponents option with get + abstract getComponent: Func, unit> option with get + abstract getComponents: Func, unit> option with get + abstract onEnter: EnterHook option with get + abstract onLeave: LeaveHook option with get + abstract indexRoute: PlainRoute option with get + abstract getIndexRoute: Func, unit> option with get + abstract childRoutes: ResizeArray option with get + abstract getChildRoutes: Func, unit> option with get + + and RedirectProps = + inherit React.Props + abstract path: RoutePattern option with get + abstract from: RoutePattern option with get + abstract ``to``: RoutePattern with get + abstract query: H.Query option with get + abstract state: H.LocationState option with get + + and Redirect = + inherit React.ComponentClass + + + and RedirectElement = + inherit React.ReactElement + + + and IndexRouteProps = + inherit React.Props + abstract ``component``: RouteComponent option with get + abstract components: RouteComponents option with get + abstract getComponent: Func, unit> option with get + abstract getComponents: Func, unit> option with get + abstract onEnter: EnterHook option with get + abstract onLeave: LeaveHook option with get + + and IndexRoute = + inherit React.ComponentClass + + + and IndexRouteElement = + inherit React.ReactElement + + + and IndexRedirectProps = + inherit React.Props + abstract ``to``: RoutePattern with get + abstract query: H.Query option with get + abstract state: H.LocationState option with get + + and IndexRedirect = + inherit React.ComponentClass + + + and IndexRedirectElement = + inherit React.ReactElement + + + and RouterOnContext = + inherit H.History + abstract setRouteLeaveHook: route: PlainRoute * ?hook: RouteHook -> Func + abstract isActive: pathOrLoc: H.LocationDescriptor * ?indexOnly: bool -> bool + + and HistoryMixin = + abstract history: History with get + + and LifecycleMixin = + abstract routerWillLeave: nextLocation: H.Location -> U2 + + and HistoryRoutes = + abstract listen: listener: RouterListener -> Function + abstract listenBeforeLeavingRoute: route: PlainRoute * hook: RouteHook -> unit + abstract ``match``: location: H.Location * callback: Func -> unit + abstract isActive: pathname: H.Pathname * ?query: H.Query * ?indexOnly: bool -> bool + abstract setRouteLeaveHook: route: PlainRoute * callback: RouteHook -> unit + + and MatchArgs = + abstract routes: RouteConfig option with get + abstract history: H.History option with get + abstract location: U2 option with get + abstract parseQueryString: ParseQueryString option with get + abstract stringifyQuery: StringifyQuery option with get + abstract basename: string option with get + + and MatchState = + inherit RouterState + abstract history: History with get + + type [] Globals = + static member browserHistory with get(): History = failwith "JS only" and set(v: History): unit = failwith "JS only" + static member hashHistory with get(): History = failwith "JS only" and set(v: History): unit = failwith "JS only" + static member Router with get(): Router = failwith "JS only" and set(v: Router): unit = failwith "JS only" + static member Link with get(): Link = failwith "JS only" and set(v: Link): unit = failwith "JS only" + static member IndexLink with get(): Link = failwith "JS only" and set(v: Link): unit = failwith "JS only" + static member RouterContext with get(): RouterContext = failwith "JS only" and set(v: RouterContext): unit = failwith "JS only" + static member Route with get(): Route = failwith "JS only" and set(v: Route): unit = failwith "JS only" + static member Redirect with get(): Redirect = failwith "JS only" and set(v: Redirect): unit = failwith "JS only" + static member IndexRoute with get(): IndexRoute = failwith "JS only" and set(v: IndexRoute): unit = failwith "JS only" + static member IndexRedirect with get(): IndexRedirect = failwith "JS only" and set(v: IndexRedirect): unit = failwith "JS only" + static member History with get(): React.Mixin = failwith "JS only" and set(v: React.Mixin): unit = failwith "JS only" + static member Lifecycle with get(): React.Mixin = failwith "JS only" and set(v: React.Mixin): unit = failwith "JS only" + static member RouteContext with get(): React.Mixin = failwith "JS only" and set(v: React.Mixin): unit = failwith "JS only" + static member createMemoryHistory(?options: H.HistoryOptions): H.History = failwith "JS only" + static member useRoutes(createHistory: HistoryModule.CreateHistory<'T>): HistoryModule.CreateHistory = failwith "JS only" + static member createRoutes(routes: RouteConfig): ResizeArray = failwith "JS only" + static member ``match``(args: MatchArgs, cb: Func): unit = failwith "JS only" + + + +module ReactRouterPatternUtils = + type [] Globals = + static member formatPattern(pattern: string, ``params``: obj): string = failwith "JS only" + + + +module ReactRouterRouteUtils = + type E = ReactElement + + type [] Globals = + static member isReactChildren(``object``: U2>): bool = failwith "JS only" + static member createRouteFromReactElement(element: E): ReactRouter.PlainRoute = failwith "JS only" + static member createRoutesFromReactChildren(children: U2>, parentRoute: ReactRouter.PlainRoute): ResizeArray = failwith "JS only" + + + +module ReactRouterPropTypes = + type [] Globals = + static member history with get(): React.Requireable = failwith "JS only" and set(v: React.Requireable): unit = failwith "JS only" + static member location with get(): React.Requireable = failwith "JS only" and set(v: React.Requireable): unit = failwith "JS only" + static member ``component`` with get(): React.Requireable = failwith "JS only" and set(v: React.Requireable): unit = failwith "JS only" + static member components with get(): React.Requireable = failwith "JS only" and set(v: React.Requireable): unit = failwith "JS only" + static member route with get(): React.Requireable = failwith "JS only" and set(v: React.Requireable): unit = failwith "JS only" + static member routes with get(): React.Requireable = failwith "JS only" and set(v: React.Requireable): unit = failwith "JS only" + static member routerShape with get(): React.Requireable = failwith "JS only" and set(v: React.Requireable): unit = failwith "JS only" + static member locationShape with get(): React.Requireable = failwith "JS only" and set(v: React.Requireable): unit = failwith "JS only" + static member falsy(props: obj, propName: string, componentName: string): Error = failwith "JS only" + + + +module ReactRouteruseRouterHistory = + type CreateRouterHistory = + [] abstract Invoke: ?options: HistoryModule.HistoryOptions -> obj + + type [] Globals = + static member useRouterHistory(createHistory: HistoryModule.CreateHistory<'T>): CreateRouterHistory = failwith "JS only" diff --git a/import/react-router/README.md b/import/react-router/README.md new file mode 100644 index 0000000000..b9fc2dbe7c --- /dev/null +++ b/import/react-router/README.md @@ -0,0 +1,36 @@ +# fable-import-react-router + +Fable bindings for React Router (react-router) 2.0.0 and History 2.0.0. +These were generated from Typescript definitions but required some manual +modification, most significantly of certain History module names. In +addition, setters were removed from all types. + +## Installation + +```sh +$ npm install --save react-router fable-core +$ npm install --save-dev fable-import-react-router +``` + +## Usage + +### In a F# project (.fsproj) + +```xml + + + + + +``` + +### In a F# script (.fsx) + +```fsharp +#r "node_modules/fable-core/Fable.Core.dll" +#load "node_modules/fable-import-react-router/Fable.Import.HistoryModule.fs" +#load "node_modules/fable-import-react-router/Fable.Import.ReactRouter.fs" + +open Fable.Core +open Fable.Import +``` diff --git a/import/react-router/history.d.ts b/import/react-router/history.d.ts new file mode 100644 index 0000000000..5f94ea3657 --- /dev/null +++ b/import/react-router/history.d.ts @@ -0,0 +1,236 @@ +// Type definitions for history v2.0.0 +// Project: https://github.com/rackt/history +// Definitions by: Sergey Buturlakin , Nathan Brown +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + + +declare namespace HistoryModule { + + // types based on https://github.com/rackt/history/blob/master/docs/Terms.md + + type Action = string + + type BeforeUnloadHook = () => string | boolean + + type CreateHistory = (options?: HistoryOptions) => T + + type CreateHistoryEnhancer = (createHistory: CreateHistory) => CreateHistory + + interface History { + listenBefore(hook: TransitionHook): () => void + listen(listener: LocationListener): () => void + transitionTo(location: Location): void + push(path: LocationDescriptor): void + replace(path: LocationDescriptor): void + go(n: number): void + goBack(): void + goForward(): void + createKey(): LocationKey + createPath(path: LocationDescriptor): Path + createHref(path: LocationDescriptor): Href + createLocation(path?: LocationDescriptor, action?: Action, key?: LocationKey): Location + + /** @deprecated use a location descriptor instead */ + createLocation(path?: Path, state?: LocationState, action?: Action, key?: LocationKey): Location + /** @deprecated use location.key to save state instead */ + pushState(state: LocationState, path: Path): void + /** @deprecated use location.key to save state instead */ + replaceState(state: LocationState, path: Path): void + /** @deprecated use location.key to save state instead */ + setState(state: LocationState): void + /** @deprecated use listenBefore instead */ + registerTransitionHook(hook: TransitionHook): void + /** @deprecated use the callback returned from listenBefore instead */ + unregisterTransitionHook(hook: TransitionHook): void + } + + type HistoryOptions = { + getCurrentLocation?: () => Location + finishTransition?: (nextLocation: Location) => boolean + saveState?: (key: LocationKey, state: LocationState) => void + go?: (n: number) => void + getUserConfirmation?: (message: string, callback: (result: boolean) => void) => void + keyLength?: number + queryKey?: string | boolean + stringifyQuery?: (obj: any) => string + parseQueryString?: (str: string) => any + basename?: string + entries?: string | [any] + current?: number + } + + type Href = string + + type Location = { + pathname: Pathname + search: Search + query: Query + state: LocationState + action: Action + key: LocationKey + hash: Hash + basename?: string + } + + type LocationDescriptorObject = { + pathname?: Pathname + search?: Search + query?: Query + state?: LocationState + } + + type LocationDescriptor = LocationDescriptorObject | Path + + type LocationKey = string + + type LocationListener = (location: Location) => void + + type LocationState = Object + + type Path = string // Pathname + QueryString + + type Pathname = string + + type Query = { [key: string]: any; } + + type QueryString = string + + type Search = string + + type TransitionHook = (location: Location, callback: (result: any) => void) => any + + type Hash = string + + + interface HistoryBeforeUnload { + listenBeforeUnload(hook: BeforeUnloadHook): () => void + } + + interface HistoryQueries { + pushState(state: LocationState, pathname: Pathname | Path, query?: Query): void + replaceState(state: LocationState, pathname: Pathname | Path, query?: Query): void + createPath(path: Path, query?: Query): Path + createHref(path: Path, query?: Query): Href + } + + + // Global usage, without modules, needs the small trick, because lib.d.ts + // already has `history` and `History` global definitions: + // var createHistory = ((window as any).History as HistoryModule.Module).createHistory; + interface Module { + createHistory: CreateHistory + createHashHistory: CreateHistory + createMemoryHistory: CreateHistory + createLocation(path?: Path, state?: LocationState, action?: Action, key?: LocationKey): Location + useBasename(createHistory: CreateHistory): CreateHistory + useBeforeUnload(createHistory: CreateHistory): CreateHistory + useQueries(createHistory: CreateHistory): CreateHistory + actions: { + PUSH: string + REPLACE: string + POP: string + } + } + +} + + +declare module "history/lib/createBrowserHistory" { + + export default function createBrowserHistory(options?: HistoryModule.HistoryOptions): HistoryModule.History + +} + + +declare module "history/lib/createHashHistory" { + + export default function createHashHistory(options?: HistoryModule.HistoryOptions): HistoryModule.History + +} + + +declare module "history/lib/createMemoryHistory" { + + export default function createMemoryHistory(options?: HistoryModule.HistoryOptions): HistoryModule.History + +} + + +declare module "history/lib/createLocation" { + + export default function createLocation(path?: HistoryModule.Path, state?: HistoryModule.LocationState, action?: HistoryModule.Action, key?: HistoryModule.LocationKey): HistoryModule.Location + +} + + +declare module "history/lib/useBasename" { + + export default function useBasename(createHistory: HistoryModule.CreateHistory): HistoryModule.CreateHistory + +} + + +declare module "history/lib/useBeforeUnload" { + + export default function useBeforeUnload(createHistory: HistoryModule.CreateHistory): HistoryModule.CreateHistory + +} + + +declare module "history/lib/useQueries" { + + export default function useQueries(createHistory: HistoryModule.CreateHistory): HistoryModule.CreateHistory + +} + + +declare module "history/lib/actions" { + + export const PUSH: string + + export const REPLACE: string + + export const POP: string + + export default { + PUSH, + REPLACE, + POP + } + +} + +declare module "history/lib/DOMUtils" { + export function addEventListener(node: EventTarget, event: string, listener: EventListenerOrEventListenerObject): void; + export function removeEventListener(node: EventTarget, event: string, listener: EventListenerOrEventListenerObject): void; + export function getHashPath(): string; + export function replaceHashPath(path: string): void; + export function getWindowPath(): string; + export function go(n: number): void; + export function getUserConfirmation(message: string, callback: (result: boolean) => void): void; + export function supportsHistory(): boolean; + export function supportsGoWithoutReloadUsingHash(): boolean; +} + + +declare module "history" { + + export { default as createHistory } from "history/lib/createBrowserHistory" + + export { default as createHashHistory } from "history/lib/createHashHistory" + + export { default as createMemoryHistory } from "history/lib/createMemoryHistory" + + export { default as createLocation } from "history/lib/createLocation" + + export { default as useBasename } from "history/lib/useBasename" + + export { default as useBeforeUnload } from "history/lib/useBeforeUnload" + + export { default as useQueries } from "history/lib/useQueries" + + import * as Actions from "history/lib/actions" + + export { Actions } + +} diff --git a/import/react-router/package.json b/import/react-router/package.json new file mode 100644 index 0000000000..7f634ca07e --- /dev/null +++ b/import/react-router/package.json @@ -0,0 +1,13 @@ +{ + "name": "fable-import-react-router", + "version": "0.0.1", + "description": "Fable bindings for React Router (react-router) 2.0.0 ", + "repository": { + "type": "git", + "url": "https://github.com/fsprojects/Fable/import/react-router-redux" + }, + "license": "Apache-2.0", + "author": "Paul Blair", + "keywords": [ "fable", "fable-compiler", "fsharp", "F#", "React" ], + "homepage": "https://github.com/fsprojects/Fable#readme" +} diff --git a/import/react-router/react-router.d.ts b/import/react-router/react-router.d.ts new file mode 100644 index 0000000000..615f0bb355 --- /dev/null +++ b/import/react-router/react-router.d.ts @@ -0,0 +1,513 @@ +// Type definitions for react-router v2.0.0 +// Project: https://github.com/rackt/react-router +// Definitions by: Sergey Buturlakin , Yuichi Murata , Václav Ostrožlík , Nathan Brown +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + + +/// +/// + + +declare namespace ReactRouter { + + import React = __React + + import H = HistoryModule + + // types based on https://github.com/rackt/react-router/blob/master/docs/Glossary.md + + type Component = React.ReactType + + type EnterHook = (nextState: RouterState, replace: RedirectFunction, callback?: Function) => void + + type LeaveHook = () => void + + type ChangeHook = (prevState: RouterState, nextState: RouterState, replace: RedirectFunction, callback: Function) => void; + + type Params = { [param: string]: string } + + type ParseQueryString = (queryString: H.QueryString) => H.Query + + interface RedirectFunction { + (location: H.LocationDescriptor): void; + /** + * @deprecated `replaceState(state, pathname, query) is deprecated; Use `replace(location)` with a location descriptor instead. http://tiny.cc/router-isActivedeprecated + */ + (state: H.LocationState, pathname: H.Pathname | H.Path, query?: H.Query): void; + } + + type RouteComponent = Component + + // use the following interface in an app code to get access to route param values, history, location... + // interface MyComponentProps extends ReactRouter.RouteComponentProps<{}, { id: number }> {} + // somewhere in MyComponent + // ... + // let id = this.props.routeParams.id + // ... + // this.props.history. ... + // ... + interface RouteComponentProps { + history?: History + location?: H.Location + params?: P + route?: PlainRoute + routeParams?: R + routes?: PlainRoute[] + children?: React.ReactElement + } + + type RouteComponents = { [key: string]: RouteComponent } + + type RouteConfig = React.ReactNode | PlainRoute | PlainRoute[] + + type RouteHook = (nextLocation?: H.Location) => any + + type RoutePattern = string + + type StringifyQuery = (queryObject: H.Query) => H.QueryString + + type RouterListener = (error: Error, nextState: RouterState) => void + + interface RouterState { + location: H.Location + routes: PlainRoute[] + params: Params + components: RouteComponent[] + } + + + interface HistoryBase extends H.History { + routes: PlainRoute[] + parseQueryString?: ParseQueryString + stringifyQuery?: StringifyQuery + } + + type History = HistoryBase & H.HistoryQueries & HistoryRoutes + const browserHistory: History; + const hashHistory: History; + + function createMemoryHistory(options?: H.HistoryOptions): H.History + + /* components */ + + interface RouterProps extends React.Props { + history?: H.History + routes?: RouteConfig // alias for children + createElement?: (component: RouteComponent, props: Object) => any + onError?: (error: any) => any + onUpdate?: () => any + parseQueryString?: ParseQueryString + stringifyQuery?: StringifyQuery + } + interface Router extends React.ComponentClass {} + interface RouterElement extends React.ReactElement {} + const Router: Router + + + interface LinkProps extends React.HTMLAttributes, React.Props { + activeStyle?: React.CSSProperties + activeClassName?: string + onlyActiveOnIndex?: boolean + to: RoutePattern | H.LocationDescriptor + query?: H.Query + state?: H.LocationState + } + interface Link extends React.ComponentClass {} + interface LinkElement extends React.ReactElement {} + const Link: Link + + + const IndexLink: Link + + + interface RouterContextProps extends React.Props { + history?: H.History + router: Router + createElement: (component: RouteComponent, props: Object) => any + location: H.Location + routes: RouteConfig + params: Params + components?: RouteComponent[] + } + interface RouterContext extends React.ComponentClass {} + interface RouterContextElement extends React.ReactElement { + history?: H.History + location: H.Location + router?: Router + } + const RouterContext: RouterContext + + + /* components (configuration) */ + + interface RouteProps extends React.Props { + path?: RoutePattern + component?: RouteComponent + components?: RouteComponents + getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void + getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void + onEnter?: EnterHook + onLeave?: LeaveHook + onChange?: ChangeHook + getIndexRoute?: (location: H.Location, cb: (error: any, indexRoute: RouteConfig) => void) => void + getChildRoutes?: (location: H.Location, cb: (error: any, childRoutes: RouteConfig) => void) => void + } + interface Route extends React.ComponentClass {} + interface RouteElement extends React.ReactElement {} + const Route: Route + + + interface PlainRoute { + path?: RoutePattern + component?: RouteComponent + components?: RouteComponents + getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void + getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void + onEnter?: EnterHook + onLeave?: LeaveHook + indexRoute?: PlainRoute + getIndexRoute?: (location: H.Location, cb: (error: any, indexRoute: RouteConfig) => void) => void + childRoutes?: PlainRoute[] + getChildRoutes?: (location: H.Location, cb: (error: any, childRoutes: RouteConfig) => void) => void + } + + + interface RedirectProps extends React.Props { + path?: RoutePattern + from?: RoutePattern // alias for path + to: RoutePattern + query?: H.Query + state?: H.LocationState + } + interface Redirect extends React.ComponentClass {} + interface RedirectElement extends React.ReactElement {} + const Redirect: Redirect + + + interface IndexRouteProps extends React.Props { + component?: RouteComponent + components?: RouteComponents + getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void + getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void + onEnter?: EnterHook + onLeave?: LeaveHook + } + interface IndexRoute extends React.ComponentClass {} + interface IndexRouteElement extends React.ReactElement {} + const IndexRoute: IndexRoute + + + interface IndexRedirectProps extends React.Props { + to: RoutePattern + query?: H.Query + state?: H.LocationState + } + interface IndexRedirect extends React.ComponentClass {} + interface IndexRedirectElement extends React.ReactElement {} + const IndexRedirect: IndexRedirect + + interface RouterOnContext extends H.History { + setRouteLeaveHook(route: PlainRoute, hook?: RouteHook): () => void; + isActive(pathOrLoc: H.LocationDescriptor, indexOnly?: boolean): boolean; + } + + /* mixins */ + + interface HistoryMixin { + history: History + } + const History: React.Mixin + + + interface LifecycleMixin { + routerWillLeave(nextLocation: H.Location): string | boolean + } + const Lifecycle: React.Mixin + + + const RouteContext: React.Mixin + + + /* utils */ + + interface HistoryRoutes { + listen(listener: RouterListener): Function + listenBeforeLeavingRoute(route: PlainRoute, hook: RouteHook): void + match(location: H.Location, callback: (error: any, nextState: RouterState, nextLocation: H.Location) => void): void + isActive(pathname: H.Pathname, query?: H.Query, indexOnly?: boolean): boolean + setRouteLeaveHook(route: PlainRoute, callback: RouteHook): void + } + + function useRoutes(createHistory: HistoryModule.CreateHistory): HistoryModule.CreateHistory + + + function createRoutes(routes: RouteConfig): PlainRoute[] + + + interface MatchArgs { + routes?: RouteConfig + history?: H.History + location?: H.Location | string + parseQueryString?: ParseQueryString + stringifyQuery?: StringifyQuery + basename?: string + } + interface MatchState extends RouterState { + history: History + } + function match(args: MatchArgs, cb: (error: any, nextLocation: H.Location, nextState: MatchState) => void): void + +} + + +declare module "react-router/lib/Router" { + + export default ReactRouter.Router + +} + + +declare module "react-router/lib/Link" { + + export default ReactRouter.Link + +} + + +declare module "react-router/lib/IndexLink" { + + export default ReactRouter.IndexLink + +} + + +declare module "react-router/lib/IndexRedirect" { + + export default ReactRouter.IndexRedirect + +} + + +declare module "react-router/lib/IndexRoute" { + + export default ReactRouter.IndexRoute + +} + + +declare module "react-router/lib/Redirect" { + + export default ReactRouter.Redirect + +} + + +declare module "react-router/lib/Route" { + + export default ReactRouter.Route + +} + + +declare module "react-router/lib/History" { + + export default ReactRouter.History + +} + + +declare module "react-router/lib/Lifecycle" { + + export default ReactRouter.Lifecycle + +} + + +declare module "react-router/lib/RouteContext" { + + export default ReactRouter.RouteContext + +} + + +declare module "react-router/lib/useRoutes" { + + export default ReactRouter.useRoutes + +} + +declare module "react-router/lib/PatternUtils" { + + export function formatPattern(pattern: string, params: {}): string; + +} + +declare module "react-router/lib/RouteUtils" { + + type E = __React.ReactElement + + export function isReactChildren(object: E | E[]): boolean + + export function createRouteFromReactElement(element: E): ReactRouter.PlainRoute + + export function createRoutesFromReactChildren(children: E | E[], parentRoute: ReactRouter.PlainRoute): ReactRouter.PlainRoute[] + + export import createRoutes = ReactRouter.createRoutes + +} + + +declare module "react-router/lib/RouterContext" { + + export default ReactRouter.RouterContext + +} + + +declare module "react-router/lib/PropTypes" { + + import React = __React + + export function falsy(props: any, propName: string, componentName: string): Error; + + export const history: React.Requireable + + export const location: React.Requireable + + export const component: React.Requireable + + export const components: React.Requireable + + export const route: React.Requireable + + export const routes: React.Requireable + + export const routerShape: React.Requireable + + export const locationShape: React.Requireable + + export default { + falsy, + history, + location, + component, + components, + route + } + +} + +declare module "react-router/lib/browserHistory" { + export default ReactRouter.browserHistory; +} + +declare module "react-router/lib/hashHistory" { + export default ReactRouter.hashHistory; +} + +declare module "react-router/lib/match" { + + export default ReactRouter.match + +} + +declare module "react-router/lib/useRouterHistory" { + interface CreateRouterHistory { + (options?: HistoryModule.HistoryOptions): HistoryModule.History & HistoryModule.HistoryQueries; + } + + export default function useRouterHistory(createHistory: HistoryModule.CreateHistory): CreateRouterHistory; +} + +declare module "react-router/lib/createMemoryHistory" { + export default ReactRouter.createMemoryHistory; +} + +declare module "react-router" { + + import Router from "react-router/lib/Router" + + import Link from "react-router/lib/Link" + + import IndexLink from "react-router/lib/IndexLink" + + import IndexRedirect from "react-router/lib/IndexRedirect" + + import IndexRoute from "react-router/lib/IndexRoute" + + import Redirect from "react-router/lib/Redirect" + + import Route from "react-router/lib/Route" + + import History from "react-router/lib/History" + + import Lifecycle from "react-router/lib/Lifecycle" + + import RouteContext from "react-router/lib/RouteContext" + + import browserHistory from "react-router/lib/browserHistory" + + import hashHistory from "react-router/lib/hashHistory" + + import useRoutes from "react-router/lib/useRoutes" + + import { createRoutes } from "react-router/lib/RouteUtils" + + import { formatPattern } from "react-router/lib/PatternUtils" + + import RouterContext from "react-router/lib/RouterContext" + + import PropTypes from "react-router/lib/PropTypes" + + import match from "react-router/lib/match" + + import useRouterHistory from "react-router/lib/useRouterHistory"; + + import createMemoryHistory from "react-router/lib/createMemoryHistory"; + + // PlainRoute is defined in the API documented at: + // https://github.com/rackt/react-router/blob/master/docs/API.md + // but not included in any of the .../lib modules above. + export type PlainRoute = ReactRouter.PlainRoute + + // The following definitions are also very useful to export + // because by using these types lots of potential type errors + // can be exposed: + export type EnterHook = ReactRouter.EnterHook + export type LeaveHook = ReactRouter.LeaveHook + export type ParseQueryString = ReactRouter.ParseQueryString + export type RedirectFunction = ReactRouter.RedirectFunction + export type RouteComponentProps = ReactRouter.RouteComponentProps; + export type RouteHook = ReactRouter.RouteHook + export type StringifyQuery = ReactRouter.StringifyQuery + export type RouterListener = ReactRouter.RouterListener + export type RouterState = ReactRouter.RouterState + export type HistoryBase = ReactRouter.HistoryBase + export type RouterOnContext = ReactRouter.RouterOnContext + + export { + Router, + Link, + IndexLink, + IndexRedirect, + IndexRoute, + Redirect, + Route, + History, + browserHistory, + hashHistory, + Lifecycle, + RouteContext, + useRoutes, + createRoutes, + formatPattern, + RouterContext, + PropTypes, + match, + useRouterHistory, + createMemoryHistory + } + + export default Router + +} diff --git a/import/redux/Fable.Import.Redux.fs b/import/redux/Fable.Import.Redux.fs index d7f3cb019c..2884b6b9ac 100644 --- a/import/redux/Fable.Import.Redux.fs +++ b/import/redux/Fable.Import.Redux.fs @@ -4,42 +4,41 @@ open System.Text.RegularExpressions open Fable.Core open Fable.Import.JS +// Type definitions for redux v3.3.1, generated from Typescript module Redux = type ActionCreator = inherit Function [] abstract Invoke: [] args: obj[] -> obj - and Reducer = - inherit Function - [] abstract Invoke: state: obj * action: obj -> obj + and Reducer<'T, 'U> = Func<'T, 'U, 'T> and Dispatch = inherit Function [] abstract Invoke: action: obj -> obj and StoreMethods = - abstract dispatch: Dispatch with get, set + abstract dispatch: Dispatch with get abstract getState: unit -> obj and MiddlewareArg = - abstract dispatch: Dispatch with get, set - abstract getState: Function with get, set + abstract dispatch: Dispatch with get + abstract getState: Function with get and Middleware = inherit Function [] abstract Invoke: obj: MiddlewareArg -> Function and [] Store() = - member __.getReducer(): Reducer = failwith "JS only" - member __.replaceReducer(nextReducer: Reducer): unit = failwith "JS only" + member __.getReducer(): Reducer<'T,'U> = failwith "JS only" + member __.replaceReducer(nextReducer: Reducer<'T,'U>): unit = failwith "JS only" member __.dispatch(action: obj): obj = failwith "JS only" member __.getState(): obj = failwith "JS only" member __.subscribe(listener: Function): Function = failwith "JS only" type [] Globals = - static member createStore(reducer: Reducer, ?initialState: obj, ?enhancer: Function): Store = failwith "JS only" + static member createStore(reducer: Reducer<'T,'U>, ?initialState: obj, ?enhancer: Function): Store = failwith "JS only" static member bindActionCreators(actionCreators: 'T, dispatch: Dispatch): 'T = failwith "JS only" - static member combineReducers(reducers: obj): Reducer = failwith "JS only" + static member combineReducers([] reducers: Reducer<'T,'U>[]): Reducer<'T,'U> = failwith "JS only" static member applyMiddleware([] middlewares: Middleware[]): Function = failwith "JS only" static member compose([] functions: Function[]): 'T = failwith "JS only" diff --git a/import/redux/README.md b/import/redux/README.md index 05b0d5ee82..e65644014a 100644 --- a/import/redux/README.md +++ b/import/redux/README.md @@ -1,6 +1,9 @@ # fable-import-redux -Fable bindings for Redux +Fable bindings for Redux, version v3.3.1. +These were generated from Typescript, with some modifications, +namely: Reducer is type narrowing of Func, with type parameters, +and all setters are removed. ## Installation diff --git a/import/redux/package.json b/import/redux/package.json index e4697b96a1..dc56515a59 100644 --- a/import/redux/package.json +++ b/import/redux/package.json @@ -1,7 +1,7 @@ { "name": "fable-import-redux", "version": "0.0.1", - "description": "Fable bindings for Redux", + "description": "Fable bindings for Redux v3.3.1", "repository": { "type": "git", "url": "https://github.com/fsprojects/Fable/import/redux" diff --git a/import/redux/redux.d.ts b/import/redux/redux.d.ts new file mode 100644 index 0000000000..3327236c14 --- /dev/null +++ b/import/redux/redux.d.ts @@ -0,0 +1,52 @@ +// Type definitions for Redux v3.3.1 +// Project: https://github.com/rackt/redux +// Definitions by: William Buchwalter , Vincent Prouillet +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace Redux { + + interface ActionCreator extends Function { + (...args: any[]): any; + } + + interface Reducer extends Function { + (state: any, action: any): any; + } + + interface Dispatch extends Function { + (action: any): any; + } + + interface StoreMethods { + dispatch: Dispatch; + getState(): any; + } + + + interface MiddlewareArg { + dispatch: Dispatch; + getState: Function; + } + + interface Middleware extends Function { + (obj: MiddlewareArg): Function; + } + + class Store { + getReducer(): Reducer; + replaceReducer(nextReducer: Reducer): void; + dispatch(action: any): any; + getState(): any; + subscribe(listener: Function): Function; + } + + function createStore(reducer: Reducer, initialState?: any, enhancer?: Function): Store; + function bindActionCreators(actionCreators: T, dispatch: Dispatch): T; + function combineReducers(reducers: any): Reducer; + function applyMiddleware(...middlewares: Middleware[]): Function; + function compose(...functions: Function[]): T; +} + +declare module "redux" { + export = Redux; +} From 5a7727ba433c280ce2f151c85ee5d44d7ee7422c Mon Sep 17 00:00:00 2001 From: Paul Blair Date: Fri, 10 Jun 2016 01:04:09 -0400 Subject: [PATCH 4/7] Need to lowercase the modules referenced by the import statement. --- import/redux/Fable.Import.Redux.fs | 4 ++-- import/redux/README.md | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/import/redux/Fable.Import.Redux.fs b/import/redux/Fable.Import.Redux.fs index 2884b6b9ac..cfa144f4a2 100644 --- a/import/redux/Fable.Import.Redux.fs +++ b/import/redux/Fable.Import.Redux.fs @@ -28,14 +28,14 @@ module Redux = inherit Function [] abstract Invoke: obj: MiddlewareArg -> Function - and [] Store() = + and [] Store() = member __.getReducer(): Reducer<'T,'U> = failwith "JS only" member __.replaceReducer(nextReducer: Reducer<'T,'U>): unit = failwith "JS only" member __.dispatch(action: obj): obj = failwith "JS only" member __.getState(): obj = failwith "JS only" member __.subscribe(listener: Function): Function = failwith "JS only" - type [] Globals = + type [] Globals = static member createStore(reducer: Reducer<'T,'U>, ?initialState: obj, ?enhancer: Function): Store = failwith "JS only" static member bindActionCreators(actionCreators: 'T, dispatch: Dispatch): 'T = failwith "JS only" static member combineReducers([] reducers: Reducer<'T,'U>[]): Reducer<'T,'U> = failwith "JS only" diff --git a/import/redux/README.md b/import/redux/README.md index e65644014a..831b8b6745 100644 --- a/import/redux/README.md +++ b/import/redux/README.md @@ -1,9 +1,13 @@ # fable-import-redux Fable bindings for Redux, version v3.3.1. -These were generated from Typescript, with some modifications, -namely: Reducer is type narrowing of Func, with type parameters, -and all setters are removed. + +These declarations were generated from Typescript, with some modifications, +namely: + + 1. `Reducer` is a type narrowing of Func, with type parameters + 2. Lowercased the module names in the Import attributes + 3. All setters are removed. ## Installation From 5024a46de2c8941442a14205b11e94c0d86bd108 Mon Sep 17 00:00:00 2001 From: Paul Blair Date: Fri, 10 Jun 2016 11:59:22 -0400 Subject: [PATCH 5/7] Fix build error passing float where int is required. --- import/electron/Fable.Import.Electron.fs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/import/electron/Fable.Import.Electron.fs b/import/electron/Fable.Import.Electron.fs index 98560d7e8e..d6a666ce59 100644 --- a/import/electron/Fable.Import.Electron.fs +++ b/import/electron/Fable.Import.Electron.fs @@ -28,8 +28,10 @@ module Electron = member __.once(``event``: string, listener: Function): NodeJS.EventEmitter = failwith "JS only" member __.removeListener(``event``: string, listener: Function): NodeJS.EventEmitter = failwith "JS only" member __.removeAllListeners(?``event``: string): NodeJS.EventEmitter = failwith "JS only" - member __.setMaxListeners(n: float): unit = failwith "JS only" + member __.setMaxListeners(n: int): unit = failwith "JS only" + member __.getMaxListeners(): int = failwith "JS only" member __.listeners(``event``: string): ResizeArray = failwith "JS only" + member __.listenerCount(``type``: string): int = failwith "JS only" member __.emit(``event``: string, [] args: obj[]): bool = failwith "JS only" and Event = From 8c2f9d72d4ab8e85c5a1355a47865c5a80de58be Mon Sep 17 00:00:00 2001 From: Paul Blair Date: Fri, 10 Jun 2016 23:53:21 -0400 Subject: [PATCH 6/7] Fix more type issues with react-redux. --- import/react-redux/Fable.Import.ReactRedux.fs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/import/react-redux/Fable.Import.ReactRedux.fs b/import/react-redux/Fable.Import.ReactRedux.fs index 75eaac85db..39777803d1 100644 --- a/import/react-redux/Fable.Import.ReactRedux.fs +++ b/import/react-redux/Fable.Import.ReactRedux.fs @@ -8,7 +8,7 @@ open Fable.Import.Redux // Type definitions for react-redux v. 4.4.0, generated from Typescript module ReactRedux = - type [] ElementClass<'P, 'S>(?props: 'P, ?context: obj) = + type [] ElementClass<'P, 'S when 'P :> Property<'P>>(?props: 'P, ?context: obj) = inherit Component<'P, 'S>(?props = props, ?context = context) @@ -30,12 +30,12 @@ module ReactRedux = and Options = abstract ``pure``: bool with get - and Property = + and Property<'P when 'P :> Property<'P>> = abstract store: Store option with get - abstract children: Function option with get + abstract children: React.ReactElement<'P> option with get - and [] Provider(?props: Property, ?context: obj) = - inherit Component(?props = props, ?context = context) + and [] Provider<'StateType, 'PropType when 'PropType :> Property<'PropType>>(?props: Property<'PropType>, ?context: obj) = + inherit Component, 'StateType>(?props = props, ?context = context) type [] Globals = From 589eb0e13af9619864f390abace81a40b1823e40 Mon Sep 17 00:00:00 2001 From: Paul Blair Date: Sat, 11 Jun 2016 18:51:36 -0400 Subject: [PATCH 7/7] Remove Typescript interface declaration files; include link to the files on GitHub. --- import/react-redux/README.md | 2 + import/react-redux/react-redux.d.ts | 103 ---- import/react-router-redux/README.md | 2 + .../react-router-redux.d.ts | 62 --- import/react-router/README.md | 3 + import/react-router/react-router.d.ts | 513 ------------------ import/redux/README.md | 2 + import/redux/redux.d.ts | 52 -- 8 files changed, 9 insertions(+), 730 deletions(-) delete mode 100644 import/react-redux/react-redux.d.ts delete mode 100644 import/react-router-redux/react-router-redux.d.ts delete mode 100644 import/react-router/react-router.d.ts delete mode 100644 import/redux/redux.d.ts diff --git a/import/react-redux/README.md b/import/react-redux/README.md index 4d93fe3829..bd5edd9374 100644 --- a/import/react-redux/README.md +++ b/import/react-redux/README.md @@ -5,6 +5,8 @@ These were generated from the Typescript file but modified to remove setters. In addition, ElementClass needs to inherit from Component rather than trying to implement it as an interface. +Typescript source file is [here](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0b96933934c2e37a749aad8e38e23214e21e7dab/react-redux/react-redux.d.ts). + ## Installation ```sh diff --git a/import/react-redux/react-redux.d.ts b/import/react-redux/react-redux.d.ts deleted file mode 100644 index 6f05a17b6e..0000000000 --- a/import/react-redux/react-redux.d.ts +++ /dev/null @@ -1,103 +0,0 @@ -// Type definitions for react-redux 4.4.0 -// Project: https://github.com/rackt/react-redux -// Definitions by: Qubo , Sean Kelley -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// -/// - -declare module "react-redux" { - import { ComponentClass, Component, StatelessComponent, ReactNode } from 'react'; - import { Store, Dispatch, ActionCreator } from 'redux'; - - interface ComponentDecorator { - (component: ComponentClass|StatelessComponent): ComponentClass; - } - - /** - * Decorator that infers the type from the original component - * - * Can't use the above decorator because it would default the type to {} - */ - export interface InferableComponentDecorator { - |StatelessComponent

)>(component: TComponentConstruct): TComponentConstruct; - } - - /** - * Connects a React component to a Redux store. - * - * - Without arguments, just wraps the component, without changing the behavior / props - * - * - If 2 params are passed (3rd param, mergeProps, is skipped), default behavior - * is to override ownProps (as stated in the docs), so what remains is everything that's - * not a state or dispatch prop - * - * - When 3rd param is passed, we don't know if ownProps propagate and whether they - * should be valid component props, because it depends on mergeProps implementation. - * As such, it is the user's responsibility to extend ownProps interface from state or - * dispatch props or both when applicable - * - * @param mapStateToProps - * @param mapDispatchToProps - * @param mergeProps - * @param options - */ - export function connect(): InferableComponentDecorator; - - export function connect( - mapStateToProps: MapStateToProps, - mapDispatchToProps?: MapDispatchToPropsFunction|MapDispatchToPropsObject - ): ComponentDecorator; - - export function connect( - mapStateToProps: MapStateToProps, - mapDispatchToProps: MapDispatchToPropsFunction|MapDispatchToPropsObject, - mergeProps: MergeProps, - options?: Options - ): ComponentDecorator; - - interface MapStateToProps { - (state: any, ownProps?: TOwnProps): TStateProps; - } - - interface MapDispatchToPropsFunction { - (dispatch: Dispatch, ownProps?: TOwnProps): TDispatchProps; - } - - interface MapDispatchToPropsObject { - [name: string]: ActionCreator; - } - - interface MergeProps { - (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps): TStateProps & TDispatchProps; - } - - interface Options { - /** - * If true, implements shouldComponentUpdate and shallowly compares the result of mergeProps, - * preventing unnecessary updates, assuming that the component is a “pure” component - * and does not rely on any input or state other than its props and the selected Redux store’s state. - * Defaults to true. - * @default true - */ - pure?: boolean; - /** - * If true, stores a ref to the wrapped component instance and makes it available via - * getWrappedInstance() method. Defaults to false. - */ - withRef?: boolean; - } - - export interface ProviderProps { - /** - * The single Redux store in your application. - */ - store?: Store; - children?: ReactNode; - } - - /** - * Makes the Redux store available to the connect() calls in the component hierarchy below. - */ - export class Provider extends Component { } -} diff --git a/import/react-router-redux/README.md b/import/react-router-redux/README.md index 8c197a0ce6..2dde1b45fb 100644 --- a/import/react-router-redux/README.md +++ b/import/react-router-redux/README.md @@ -4,6 +4,8 @@ Fable bindings for the Redux React Router (react-router-redux) bindings, v4.0.0. These were generated from Typescript, with some modifications: namely, all setters were removed, and type parameters were provided when `Reducer` is used. +Typescript source file is [here](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/56295f5058cac7ae458540423c50ac2dcf9fc711/react-router-redux/react-router-redux.d.ts). + ## Installation ```sh diff --git a/import/react-router-redux/react-router-redux.d.ts b/import/react-router-redux/react-router-redux.d.ts deleted file mode 100644 index b2c993132a..0000000000 --- a/import/react-router-redux/react-router-redux.d.ts +++ /dev/null @@ -1,62 +0,0 @@ -// Type definitions for react-router-redux v4.0.0 -// Project: https://github.com/rackt/react-router-redux -// Definitions by: Isman Usoh , Noah Shipley , Dimitri Rosenberg -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// -/// - -declare namespace ReactRouterRedux { - import R = Redux; - import H = HistoryModule; - - const CALL_HISTORY_METHOD: string; - const LOCATION_CHANGE: string; - - const push: PushAction; - const replace: ReplaceAction; - const go: GoAction; - const goBack: GoForwardAction; - const goForward: GoBackAction; - const routerActions: RouteActions; - - type LocationDescriptor = H.Location | H.Path; - type PushAction = (nextLocation: LocationDescriptor) => RouterAction; - type ReplaceAction = (nextLocation: LocationDescriptor) => RouterAction; - type GoAction = (n: number) => RouterAction; - type GoForwardAction = () => RouterAction; - type GoBackAction = () => RouterAction; - - type RouterAction = { - type: string - payload?: any - } - - interface RouteActions { - push: PushAction; - replace: ReplaceAction; - go: GoAction; - goForward: GoForwardAction; - goBack: GoBackAction; - } - interface ReactRouterReduxHistory extends H.History { - unsubscribe(): void; - } - - interface DefaultSelectLocationState extends Function { - (state: any): any; - } - - interface SyncHistoryWithStoreOptions { - selectLocationState?: DefaultSelectLocationState; - adjustUrlOnReplay?: boolean; - } - - function routerReducer(state?: any, options?: any): R.Reducer; - function syncHistoryWithStore(history: H.History, store: R.Store, options?: SyncHistoryWithStoreOptions): ReactRouterReduxHistory; - function routerMiddleware(history: H.History): R.Middleware; -} - -declare module "react-router-redux" { - export = ReactRouterRedux; -} diff --git a/import/react-router/README.md b/import/react-router/README.md index b9fc2dbe7c..9969c8764e 100644 --- a/import/react-router/README.md +++ b/import/react-router/README.md @@ -5,6 +5,9 @@ These were generated from Typescript definitions but required some manual modification, most significantly of certain History module names. In addition, setters were removed from all types. +Typescript source file is [here](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/df9065dc6e93d23a0d284c57c30570eefb81d35d/react-router/react-router.d.ts). + + ## Installation ```sh diff --git a/import/react-router/react-router.d.ts b/import/react-router/react-router.d.ts deleted file mode 100644 index 615f0bb355..0000000000 --- a/import/react-router/react-router.d.ts +++ /dev/null @@ -1,513 +0,0 @@ -// Type definitions for react-router v2.0.0 -// Project: https://github.com/rackt/react-router -// Definitions by: Sergey Buturlakin , Yuichi Murata , Václav Ostrožlík , Nathan Brown -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - - -/// -/// - - -declare namespace ReactRouter { - - import React = __React - - import H = HistoryModule - - // types based on https://github.com/rackt/react-router/blob/master/docs/Glossary.md - - type Component = React.ReactType - - type EnterHook = (nextState: RouterState, replace: RedirectFunction, callback?: Function) => void - - type LeaveHook = () => void - - type ChangeHook = (prevState: RouterState, nextState: RouterState, replace: RedirectFunction, callback: Function) => void; - - type Params = { [param: string]: string } - - type ParseQueryString = (queryString: H.QueryString) => H.Query - - interface RedirectFunction { - (location: H.LocationDescriptor): void; - /** - * @deprecated `replaceState(state, pathname, query) is deprecated; Use `replace(location)` with a location descriptor instead. http://tiny.cc/router-isActivedeprecated - */ - (state: H.LocationState, pathname: H.Pathname | H.Path, query?: H.Query): void; - } - - type RouteComponent = Component - - // use the following interface in an app code to get access to route param values, history, location... - // interface MyComponentProps extends ReactRouter.RouteComponentProps<{}, { id: number }> {} - // somewhere in MyComponent - // ... - // let id = this.props.routeParams.id - // ... - // this.props.history. ... - // ... - interface RouteComponentProps { - history?: History - location?: H.Location - params?: P - route?: PlainRoute - routeParams?: R - routes?: PlainRoute[] - children?: React.ReactElement - } - - type RouteComponents = { [key: string]: RouteComponent } - - type RouteConfig = React.ReactNode | PlainRoute | PlainRoute[] - - type RouteHook = (nextLocation?: H.Location) => any - - type RoutePattern = string - - type StringifyQuery = (queryObject: H.Query) => H.QueryString - - type RouterListener = (error: Error, nextState: RouterState) => void - - interface RouterState { - location: H.Location - routes: PlainRoute[] - params: Params - components: RouteComponent[] - } - - - interface HistoryBase extends H.History { - routes: PlainRoute[] - parseQueryString?: ParseQueryString - stringifyQuery?: StringifyQuery - } - - type History = HistoryBase & H.HistoryQueries & HistoryRoutes - const browserHistory: History; - const hashHistory: History; - - function createMemoryHistory(options?: H.HistoryOptions): H.History - - /* components */ - - interface RouterProps extends React.Props { - history?: H.History - routes?: RouteConfig // alias for children - createElement?: (component: RouteComponent, props: Object) => any - onError?: (error: any) => any - onUpdate?: () => any - parseQueryString?: ParseQueryString - stringifyQuery?: StringifyQuery - } - interface Router extends React.ComponentClass {} - interface RouterElement extends React.ReactElement {} - const Router: Router - - - interface LinkProps extends React.HTMLAttributes, React.Props { - activeStyle?: React.CSSProperties - activeClassName?: string - onlyActiveOnIndex?: boolean - to: RoutePattern | H.LocationDescriptor - query?: H.Query - state?: H.LocationState - } - interface Link extends React.ComponentClass {} - interface LinkElement extends React.ReactElement {} - const Link: Link - - - const IndexLink: Link - - - interface RouterContextProps extends React.Props { - history?: H.History - router: Router - createElement: (component: RouteComponent, props: Object) => any - location: H.Location - routes: RouteConfig - params: Params - components?: RouteComponent[] - } - interface RouterContext extends React.ComponentClass {} - interface RouterContextElement extends React.ReactElement { - history?: H.History - location: H.Location - router?: Router - } - const RouterContext: RouterContext - - - /* components (configuration) */ - - interface RouteProps extends React.Props { - path?: RoutePattern - component?: RouteComponent - components?: RouteComponents - getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void - getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void - onEnter?: EnterHook - onLeave?: LeaveHook - onChange?: ChangeHook - getIndexRoute?: (location: H.Location, cb: (error: any, indexRoute: RouteConfig) => void) => void - getChildRoutes?: (location: H.Location, cb: (error: any, childRoutes: RouteConfig) => void) => void - } - interface Route extends React.ComponentClass {} - interface RouteElement extends React.ReactElement {} - const Route: Route - - - interface PlainRoute { - path?: RoutePattern - component?: RouteComponent - components?: RouteComponents - getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void - getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void - onEnter?: EnterHook - onLeave?: LeaveHook - indexRoute?: PlainRoute - getIndexRoute?: (location: H.Location, cb: (error: any, indexRoute: RouteConfig) => void) => void - childRoutes?: PlainRoute[] - getChildRoutes?: (location: H.Location, cb: (error: any, childRoutes: RouteConfig) => void) => void - } - - - interface RedirectProps extends React.Props { - path?: RoutePattern - from?: RoutePattern // alias for path - to: RoutePattern - query?: H.Query - state?: H.LocationState - } - interface Redirect extends React.ComponentClass {} - interface RedirectElement extends React.ReactElement {} - const Redirect: Redirect - - - interface IndexRouteProps extends React.Props { - component?: RouteComponent - components?: RouteComponents - getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void - getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void - onEnter?: EnterHook - onLeave?: LeaveHook - } - interface IndexRoute extends React.ComponentClass {} - interface IndexRouteElement extends React.ReactElement {} - const IndexRoute: IndexRoute - - - interface IndexRedirectProps extends React.Props { - to: RoutePattern - query?: H.Query - state?: H.LocationState - } - interface IndexRedirect extends React.ComponentClass {} - interface IndexRedirectElement extends React.ReactElement {} - const IndexRedirect: IndexRedirect - - interface RouterOnContext extends H.History { - setRouteLeaveHook(route: PlainRoute, hook?: RouteHook): () => void; - isActive(pathOrLoc: H.LocationDescriptor, indexOnly?: boolean): boolean; - } - - /* mixins */ - - interface HistoryMixin { - history: History - } - const History: React.Mixin - - - interface LifecycleMixin { - routerWillLeave(nextLocation: H.Location): string | boolean - } - const Lifecycle: React.Mixin - - - const RouteContext: React.Mixin - - - /* utils */ - - interface HistoryRoutes { - listen(listener: RouterListener): Function - listenBeforeLeavingRoute(route: PlainRoute, hook: RouteHook): void - match(location: H.Location, callback: (error: any, nextState: RouterState, nextLocation: H.Location) => void): void - isActive(pathname: H.Pathname, query?: H.Query, indexOnly?: boolean): boolean - setRouteLeaveHook(route: PlainRoute, callback: RouteHook): void - } - - function useRoutes(createHistory: HistoryModule.CreateHistory): HistoryModule.CreateHistory - - - function createRoutes(routes: RouteConfig): PlainRoute[] - - - interface MatchArgs { - routes?: RouteConfig - history?: H.History - location?: H.Location | string - parseQueryString?: ParseQueryString - stringifyQuery?: StringifyQuery - basename?: string - } - interface MatchState extends RouterState { - history: History - } - function match(args: MatchArgs, cb: (error: any, nextLocation: H.Location, nextState: MatchState) => void): void - -} - - -declare module "react-router/lib/Router" { - - export default ReactRouter.Router - -} - - -declare module "react-router/lib/Link" { - - export default ReactRouter.Link - -} - - -declare module "react-router/lib/IndexLink" { - - export default ReactRouter.IndexLink - -} - - -declare module "react-router/lib/IndexRedirect" { - - export default ReactRouter.IndexRedirect - -} - - -declare module "react-router/lib/IndexRoute" { - - export default ReactRouter.IndexRoute - -} - - -declare module "react-router/lib/Redirect" { - - export default ReactRouter.Redirect - -} - - -declare module "react-router/lib/Route" { - - export default ReactRouter.Route - -} - - -declare module "react-router/lib/History" { - - export default ReactRouter.History - -} - - -declare module "react-router/lib/Lifecycle" { - - export default ReactRouter.Lifecycle - -} - - -declare module "react-router/lib/RouteContext" { - - export default ReactRouter.RouteContext - -} - - -declare module "react-router/lib/useRoutes" { - - export default ReactRouter.useRoutes - -} - -declare module "react-router/lib/PatternUtils" { - - export function formatPattern(pattern: string, params: {}): string; - -} - -declare module "react-router/lib/RouteUtils" { - - type E = __React.ReactElement - - export function isReactChildren(object: E | E[]): boolean - - export function createRouteFromReactElement(element: E): ReactRouter.PlainRoute - - export function createRoutesFromReactChildren(children: E | E[], parentRoute: ReactRouter.PlainRoute): ReactRouter.PlainRoute[] - - export import createRoutes = ReactRouter.createRoutes - -} - - -declare module "react-router/lib/RouterContext" { - - export default ReactRouter.RouterContext - -} - - -declare module "react-router/lib/PropTypes" { - - import React = __React - - export function falsy(props: any, propName: string, componentName: string): Error; - - export const history: React.Requireable - - export const location: React.Requireable - - export const component: React.Requireable - - export const components: React.Requireable - - export const route: React.Requireable - - export const routes: React.Requireable - - export const routerShape: React.Requireable - - export const locationShape: React.Requireable - - export default { - falsy, - history, - location, - component, - components, - route - } - -} - -declare module "react-router/lib/browserHistory" { - export default ReactRouter.browserHistory; -} - -declare module "react-router/lib/hashHistory" { - export default ReactRouter.hashHistory; -} - -declare module "react-router/lib/match" { - - export default ReactRouter.match - -} - -declare module "react-router/lib/useRouterHistory" { - interface CreateRouterHistory { - (options?: HistoryModule.HistoryOptions): HistoryModule.History & HistoryModule.HistoryQueries; - } - - export default function useRouterHistory(createHistory: HistoryModule.CreateHistory): CreateRouterHistory; -} - -declare module "react-router/lib/createMemoryHistory" { - export default ReactRouter.createMemoryHistory; -} - -declare module "react-router" { - - import Router from "react-router/lib/Router" - - import Link from "react-router/lib/Link" - - import IndexLink from "react-router/lib/IndexLink" - - import IndexRedirect from "react-router/lib/IndexRedirect" - - import IndexRoute from "react-router/lib/IndexRoute" - - import Redirect from "react-router/lib/Redirect" - - import Route from "react-router/lib/Route" - - import History from "react-router/lib/History" - - import Lifecycle from "react-router/lib/Lifecycle" - - import RouteContext from "react-router/lib/RouteContext" - - import browserHistory from "react-router/lib/browserHistory" - - import hashHistory from "react-router/lib/hashHistory" - - import useRoutes from "react-router/lib/useRoutes" - - import { createRoutes } from "react-router/lib/RouteUtils" - - import { formatPattern } from "react-router/lib/PatternUtils" - - import RouterContext from "react-router/lib/RouterContext" - - import PropTypes from "react-router/lib/PropTypes" - - import match from "react-router/lib/match" - - import useRouterHistory from "react-router/lib/useRouterHistory"; - - import createMemoryHistory from "react-router/lib/createMemoryHistory"; - - // PlainRoute is defined in the API documented at: - // https://github.com/rackt/react-router/blob/master/docs/API.md - // but not included in any of the .../lib modules above. - export type PlainRoute = ReactRouter.PlainRoute - - // The following definitions are also very useful to export - // because by using these types lots of potential type errors - // can be exposed: - export type EnterHook = ReactRouter.EnterHook - export type LeaveHook = ReactRouter.LeaveHook - export type ParseQueryString = ReactRouter.ParseQueryString - export type RedirectFunction = ReactRouter.RedirectFunction - export type RouteComponentProps = ReactRouter.RouteComponentProps; - export type RouteHook = ReactRouter.RouteHook - export type StringifyQuery = ReactRouter.StringifyQuery - export type RouterListener = ReactRouter.RouterListener - export type RouterState = ReactRouter.RouterState - export type HistoryBase = ReactRouter.HistoryBase - export type RouterOnContext = ReactRouter.RouterOnContext - - export { - Router, - Link, - IndexLink, - IndexRedirect, - IndexRoute, - Redirect, - Route, - History, - browserHistory, - hashHistory, - Lifecycle, - RouteContext, - useRoutes, - createRoutes, - formatPattern, - RouterContext, - PropTypes, - match, - useRouterHistory, - createMemoryHistory - } - - export default Router - -} diff --git a/import/redux/README.md b/import/redux/README.md index 831b8b6745..f716b58c07 100644 --- a/import/redux/README.md +++ b/import/redux/README.md @@ -9,6 +9,8 @@ namely: 2. Lowercased the module names in the Import attributes 3. All setters are removed. +Typescript source file is [here](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/c2bfaedeee7ae4ed5e0f01ebcf4af7acfe2c77c3/redux/redux.d.ts). + ## Installation ```sh diff --git a/import/redux/redux.d.ts b/import/redux/redux.d.ts deleted file mode 100644 index 3327236c14..0000000000 --- a/import/redux/redux.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -// Type definitions for Redux v3.3.1 -// Project: https://github.com/rackt/redux -// Definitions by: William Buchwalter , Vincent Prouillet -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare namespace Redux { - - interface ActionCreator extends Function { - (...args: any[]): any; - } - - interface Reducer extends Function { - (state: any, action: any): any; - } - - interface Dispatch extends Function { - (action: any): any; - } - - interface StoreMethods { - dispatch: Dispatch; - getState(): any; - } - - - interface MiddlewareArg { - dispatch: Dispatch; - getState: Function; - } - - interface Middleware extends Function { - (obj: MiddlewareArg): Function; - } - - class Store { - getReducer(): Reducer; - replaceReducer(nextReducer: Reducer): void; - dispatch(action: any): any; - getState(): any; - subscribe(listener: Function): Function; - } - - function createStore(reducer: Reducer, initialState?: any, enhancer?: Function): Store; - function bindActionCreators(actionCreators: T, dispatch: Dispatch): T; - function combineReducers(reducers: any): Reducer; - function applyMiddleware(...middlewares: Middleware[]): Function; - function compose(...functions: Function[]): T; -} - -declare module "redux" { - export = Redux; -}