test-sorrycc-2
v0.0.14
Published
Front-end framework based on react, redux, react-redux, react-router and redux-saga, inspired by elm and choo.
Downloads
5
Maintainers
Readme
dva
Lightweight elm-style framework based on react and redux.
Documents
- dva 入门:手把手教你用写应用
- dva 简介
- React + Redux 最佳实践 (dva 基于此封装)
- subscription 及其适用场景
- 支付宝前端应用架构的发展和选择: 从 roof 到 redux 再到 dva
Getting Started
Install
$ npm install --save dva
Usage Example
Let's create an count app that changes when user click the + or - button.
import React from 'react';
import dva, { connect } from 'dva';
import { Router, Route } from 'dva/router';
// 1. Initialize
const app = dva();
// 2. Model
app.model({
namespace: 'count',
state: 0,
reducers: {
['count/add' ](count) { return count + 1 },
['count/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
app.start(document.getElementById('root'));
Examples
FAQ
dva 命名的来历 ?
dva 是守望先锋 (overwatch) 里的英雄。我喜欢使用这个角色,拥有强大的机甲,是个坚实的肉盾,并且她是唯一背景是真实的电竞选手,来自韩国。