From acb2f62ccc44cd2d6b2dff4db0804d3bbd579506 Mon Sep 17 00:00:00 2001 From: yhpnorra Date: Fri, 8 Dec 2017 19:54:51 +0800 Subject: [PATCH] add types of mirrox --- types/mirrorx/README.md | 1 + types/mirrorx/index.d.ts | 219 +++++++++++++++++++++++++++++++++ types/mirrorx/mirrorx-tests.ts | 29 +++++ types/mirrorx/package.json | 11 ++ types/mirrorx/tsconfig.json | 26 ++++ types/mirrorx/tslint.json | 7 ++ 6 files changed, 293 insertions(+) create mode 100644 types/mirrorx/README.md create mode 100644 types/mirrorx/index.d.ts create mode 100644 types/mirrorx/mirrorx-tests.ts create mode 100644 types/mirrorx/package.json create mode 100644 types/mirrorx/tsconfig.json create mode 100644 types/mirrorx/tslint.json diff --git a/types/mirrorx/README.md b/types/mirrorx/README.md new file mode 100644 index 0000000000..a4bce407a2 --- /dev/null +++ b/types/mirrorx/README.md @@ -0,0 +1 @@ +This is typings for [mirrorjs](https://github.com/mirrorjs/mirror) \ No newline at end of file diff --git a/types/mirrorx/index.d.ts b/types/mirrorx/index.d.ts new file mode 100644 index 0000000000..5720677bfe --- /dev/null +++ b/types/mirrorx/index.d.ts @@ -0,0 +1,219 @@ +// Type definitions for mirrorjs +// Project: https://github.com/mirrorjs/mirror +// Definitions by: Aaronphy +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import * as React from 'react'; +import * as H from 'history'; +import { + ReactInstance, Component, ComponentState, + ReactElement, SFCElement, CElement, + DOMAttributes, DOMElement, ReactNode, ReactPortal +} from 'react'; +import { + History, + Location, + Path, + LocationState, + LocationDescriptor +} from 'history'; + +import { Connect } from 'react-redux'; +import { match } from "react-router"; + + +export = mirror; +export as namespace mirror; + +declare namespace mirror { + + type Diff = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T]; + type Omit = Pick>; + + interface model { + name:string, + initialState?:any, + reducers?:any, + effects?:any + } + + interface _model { + name:string, + reducers:any + } + + interface LinkProps extends React.AnchorHTMLAttributes { + to: H.LocationDescriptor; + replace?: boolean; + } + + interface NavLinkProps extends LinkProps { + activeClassName?: string; + activeStyle?: React.CSSProperties; + exact?: boolean; + strict?: boolean; + isActive?

(match: match

, location: H.Location): boolean; + location?: H.Location; + } + + interface SwitchProps { + children?: React.ReactNode; + location?: H.Location; + } + + interface RedirectProps { + to: H.LocationDescriptor; + push?: boolean; + from?: string; + path?: string; + exact?: boolean; + strict?: boolean; + } + + interface RouteComponentProps

{ + match: match

; + location: H.Location; + history: H.History; + staticContext?: any; + } + + interface RouteProps { + location?: H.Location; + component?: React.ComponentType> | React.ComponentType; + render?: ((props: RouteComponentProps) => React.ReactNode); + children?: ((props: RouteComponentProps) => React.ReactNode) | React.ReactNode; + path?: string; + exact?: boolean; + strict?: boolean; + } + + interface PromptProps { + message: string | ((location: H.Location) => string | boolean); + when?: boolean; + } + + interface LocationActionPayload { + method: string; + args?: any[]; + } + + interface RouterAction { + type:'@@router/CALL_HISTORY_METHOD', + payload: LocationActionPayload; + } + + interface routeActions { + push(location:any,state?:any):RouterAction, + replace(location:any,state?:any):RouterAction, + go(n:number):RouterAction, + goBack(): RouterAction, + goForward(): RouterAction + } + + export interface ConnectedRouterProps { + store?: any; + history?: History; +} + + interface Actions { + routing:routeActions, + [propName: string]: any + } + + interface defaultOptions { + initialState?:{}, + historyMode?:string, + middlewares:[any], + reducers:{}, + addEffect(name:string,handler:()=>any):any + } + + interface Renderer { + // Deprecated(render): The return value is deprecated. + // In future releases the render function's return type will be void. + + ( + element: DOMElement, T>, + container: Element | null, + callback?: () => void + ): T; + + ( + element: Array, any>>, + container: Element | null, + callback?: () => void + ): Element; + + ( + element: SFCElement | Array>, + container: Element | null, + callback?: () => void + ): void; + + >( + element: CElement, + container: Element | null, + callback?: () => void + ): T; + + ( + element: Array>>, + container: Element | null, + callback?: () => void + ): Component; + +

( + element: ReactElement

, + container: Element | null, + callback?: () => void + ): Component | Element | void; + + ( + element: Array>, + container: Element | null, + callback?: () => void + ): Component | Element | void; + + ( + parentComponent: Component | Array>, + element: SFCElement, + container: Element, + callback?: () => void + ): void; +} + + /** + * This method is used to create and inject a model. + * @param options + */ + function model(options:model):_model + /** + * connect connects your React component to your Redux store + */ + const connect:Connect + //The actions object contains both your Redux actions and reducers. + const actions:Actions + //Add a hook to monitor actions that have been dispatched. + const hook:(subscriber:()=>any)=>any + //mirror.defaults is a pretty intuitive API, you use it to configure your Mirror app. + const defaults:(options:defaultOptions)=>void + //render is an enhanced ReactDOM.render, it starts your Mirror app. + const render: Renderer; + // Mirror uses react-router@4.x, so if you're from react-router 2.x/3.x, you should checkout the Migrating from v2/v3 to v4 Guide. + class Router extends React.Component> {} + + class Link extends React.Component {} + + class NavLink extends React.Component {} + + class Redirect extends React.Component { } + + class Route extends React.Component { } + + class Prompt extends React.Component { } + + function withRouter

>(component: React.ComponentType

): React.ComponentClass>>; + + function withRouter>(target: TFunction): TFunction; +} \ No newline at end of file diff --git a/types/mirrorx/mirrorx-tests.ts b/types/mirrorx/mirrorx-tests.ts new file mode 100644 index 0000000000..c2a1ca6616 --- /dev/null +++ b/types/mirrorx/mirrorx-tests.ts @@ -0,0 +1,29 @@ +import { Component, ReactElement } from 'react'; +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +import * as mirror from 'mirrorx'; +import { render,actions,withRouter,Link,NavLink,Router,Route,connect,Redirect} from 'mirrorx' + +mirror.model({ + name:'app', + + initialState: 0, + + reducers:{ + increment(state:any) { return state + 1 }, + decrement(state:any) { return state - 1 } + }, + + effects:{ + async incrementAsync() { + await new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, 1000) + }) + actions.app.increment() + } + } +}); + + diff --git a/types/mirrorx/package.json b/types/mirrorx/package.json new file mode 100644 index 0000000000..ee406466f8 --- /dev/null +++ b/types/mirrorx/package.json @@ -0,0 +1,11 @@ +{ + "private": true, + "dependencies": { + "@types/react":"^16.0.0", + "@types/react-dom":"^16.0.0", + "@types/react-router-dom":"^4.2.3", + "@types/redux":"^3.6.0", + "@types/react-redux":"^5.0.14", + "@types/react-router-redux":"^5.0.10" + } +} \ No newline at end of file diff --git a/types/mirrorx/tsconfig.json b/types/mirrorx/tsconfig.json new file mode 100644 index 0000000000..bc994b8f74 --- /dev/null +++ b/types/mirrorx/tsconfig.json @@ -0,0 +1,26 @@ +{ + "files": [ + "index.d.ts", + "mirrorx_test.ts" + ], + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "jsx": "react", + "experimentalDecorators": true, + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + } +} \ No newline at end of file diff --git a/types/mirrorx/tslint.json b/types/mirrorx/tslint.json new file mode 100644 index 0000000000..f7a71e1866 --- /dev/null +++ b/types/mirrorx/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": ["tslint:latest", "tslint-react"], + "rules": { + "no-unnecessary-generics": false, + "jsx-wrap-multiline": false + } +} \ No newline at end of file