mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
add dva declaration
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// <reference path="../react/react.d.ts" />
|
||||
// <reference path="./dva.d.ts" />
|
||||
|
||||
import dva from 'dva';
|
||||
import { connect } from 'dva';
|
||||
import { Router, Route } from 'dva/router';
|
||||
|
||||
// 1. Initialize
|
||||
const app = dva();
|
||||
|
||||
// 2. Model
|
||||
app.model({
|
||||
namespace: 'count',
|
||||
state: 0,
|
||||
reducers: {
|
||||
add (count) {
|
||||
return count + 1
|
||||
},
|
||||
minus(count) {
|
||||
return count - 1
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// 3. View
|
||||
const App = connect(({ count }) => ({
|
||||
count
|
||||
}))(function (props) {
|
||||
return (
|
||||
<div>
|
||||
<h2>{ props.count }</h2>
|
||||
<button key="add" onClick={() => { props.dispatch({type: 'count/add'})}}>+</button>
|
||||
<button key="minus" onClick={() => { props.dispatch({type: 'count/minus'})}}>-</button>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
// 4. Router
|
||||
app.router(({ history }) =>
|
||||
<Router history={history}>
|
||||
<Route path="/" component={App}/>
|
||||
</Router>
|
||||
);
|
||||
|
||||
// 5. Start
|
||||
const countApp = app.start();
|
||||
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
// Type definitions for dva v1.0.0
|
||||
// Project: https://github.com/dvajs/dva
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare module 'dva' {
|
||||
/** connecting Container Components */
|
||||
export function connect(maps):Function;
|
||||
|
||||
export default function dva(opts?:Object):{
|
||||
|
||||
/** dva plugin */
|
||||
use: (hooks:Object)=>void,
|
||||
|
||||
/** dva bootstrap */
|
||||
start: (selector?:Object)=>void,
|
||||
|
||||
/** dva add model */
|
||||
model: (model:Object)=>void,
|
||||
|
||||
/** dva setting router */
|
||||
router: (router)=>void,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/reactjs/react-router
|
||||
*/
|
||||
declare module 'dva/router' {
|
||||
export class Router {}
|
||||
export class Route {}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/reactjs/react-router-redux
|
||||
*/
|
||||
declare module 'dva/routerRedux' {
|
||||
export default Object;
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/fis-components/whatwg-fetch
|
||||
*/
|
||||
declare module 'dva/fetch' {
|
||||
export default Function;
|
||||
}
|
||||
Reference in New Issue
Block a user