mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
45 lines
952 B
TypeScript
45 lines
952 B
TypeScript
import dva from 'dva';
|
|
import { connect } from 'dva';
|
|
import { Router, Route } from 'dva/router';
|
|
import * as React from "react";
|
|
|
|
// 1. Initialize
|
|
const app = dva();
|
|
|
|
// 2. Model
|
|
app.model({
|
|
namespace: 'count',
|
|
state: 0,
|
|
reducers: {
|
|
add(count: number) {
|
|
return count + 1
|
|
},
|
|
minus(count: number) {
|
|
return count - 1
|
|
},
|
|
},
|
|
});
|
|
|
|
// 3. View
|
|
const App = connect(({ count }: any) => ({
|
|
count
|
|
}))(function ({ count, dispatch }: any) {
|
|
return (
|
|
<div>
|
|
<h2>{ count }</h2>
|
|
<button key="add" onClick={() => { dispatch({type: 'count/add'})}}>+</button>
|
|
<button key="minus" onClick={() => { dispatch({type: 'count/minus'})}}>-</button>
|
|
</div>
|
|
);
|
|
});
|
|
|
|
// 4. Router
|
|
app.router(({ history }: any) =>
|
|
<Router history={history}>
|
|
<Route path="/" component={App}/>
|
|
</Router>
|
|
);
|
|
|
|
// 5. Start
|
|
const countApp = app.start();
|