add types of mirrox

This commit is contained in:
yhpnorra
2017-12-11 11:18:46 +08:00
committed by yhpnorra
parent 95a6956b87
commit acb2f62ccc
6 changed files with 293 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
This is typings for [mirrorjs](https://github.com/mirrorjs/mirror)
+219
View File
@@ -0,0 +1,219 @@
// Type definitions for mirrorjs
// Project: https://github.com/mirrorjs/mirror
// Definitions by: Aaronphy <https://github.com/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<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;
interface model {
name:string,
initialState?:any,
reducers?:any,
effects?:any
}
interface _model {
name:string,
reducers:any
}
interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
to: H.LocationDescriptor;
replace?: boolean;
}
interface NavLinkProps extends LinkProps {
activeClassName?: string;
activeStyle?: React.CSSProperties;
exact?: boolean;
strict?: boolean;
isActive?<P>(match: match<P>, 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<P> {
match: match<P>;
location: H.Location;
history: H.History;
staticContext?: any;
}
interface RouteProps {
location?: H.Location;
component?: React.ComponentType<RouteComponentProps<any>> | React.ComponentType<any>;
render?: ((props: RouteComponentProps<any>) => React.ReactNode);
children?: ((props: RouteComponentProps<any>) => 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<State> {
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.
<T extends Element>(
element: DOMElement<DOMAttributes<T>, T>,
container: Element | null,
callback?: () => void
): T;
(
element: Array<DOMElement<DOMAttributes<any>, any>>,
container: Element | null,
callback?: () => void
): Element;
(
element: SFCElement<any> | Array<SFCElement<any>>,
container: Element | null,
callback?: () => void
): void;
<P, T extends Component<P, ComponentState>>(
element: CElement<P, T>,
container: Element | null,
callback?: () => void
): T;
(
element: Array<CElement<any, Component<any, ComponentState>>>,
container: Element | null,
callback?: () => void
): Component<any, ComponentState>;
<P>(
element: ReactElement<P>,
container: Element | null,
callback?: () => void
): Component<P, ComponentState> | Element | void;
(
element: Array<ReactElement<any>>,
container: Element | null,
callback?: () => void
): Component<any, ComponentState> | Element | void;
(
parentComponent: Component<any> | Array<Component<any>>,
element: SFCElement<any>,
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<State> extends React.Component<ConnectedRouterProps<State>> {}
class Link extends React.Component<LinkProps, any> {}
class NavLink extends React.Component<NavLinkProps, any> {}
class Redirect extends React.Component<RedirectProps, any> { }
class Route<T extends RouteProps = RouteProps> extends React.Component<T, any> { }
class Prompt extends React.Component<PromptProps, any> { }
function withRouter<P extends RouteComponentProps<any>>(component: React.ComponentType<P>): React.ComponentClass<Omit<P, keyof RouteComponentProps<any>>>;
function withRouter<P, TFunction extends React.ComponentClass<P>>(target: TFunction): TFunction;
}
+29
View File
@@ -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()
}
}
});
+11
View File
@@ -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"
}
}
+26
View File
@@ -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
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"extends": ["tslint:latest", "tslint-react"],
"rules": {
"no-unnecessary-generics": false,
"jsx-wrap-multiline": false
}
}