-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7f38785
Showing
17 changed files
with
469 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.DS_Store | ||
tmp | ||
node_modules | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
node_modules | ||
coverage | ||
test/fixtures | ||
test/expected | ||
tmp | ||
demo | ||
spm_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"expr": true, | ||
"eqeqeq": true, | ||
"eqnull": true, | ||
"indent": 2, | ||
"latedef": "nofunc", | ||
"newcap": true, | ||
"quotmark": true, | ||
"trailing": true, | ||
"undef": true, | ||
"unused": true, | ||
"lastsemic": true, | ||
"boss": true, | ||
"funcscope": true, | ||
"loopfunc": true, | ||
"smarttabs": true, | ||
"sub": true, | ||
"strict": true, | ||
"node": true, | ||
"esnext": true, | ||
"globals": { | ||
"describe": false, | ||
"xdescribe": false, | ||
"it": false, | ||
"xit": false, | ||
"before": false, | ||
"beforeEach": false, | ||
"after": false, | ||
"afterEach": false, | ||
"define": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
publish: | ||
npm publish | ||
|
||
publish-sync: publish | ||
cnpm sync dva | ||
tnpm sync dva |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# dva | ||
|
||
[![NPM version](https://img.shields.io/npm/v/dva.svg?style=flat)](https://npmjs.org/package/dva) | ||
|
||
Front-end framework based on react, redux, react-redux, react-router and redux-saga, inspired by elm and choo. | ||
|
||
---- | ||
|
||
## Quick start with count | ||
|
||
```javascript | ||
import React from 'react'; | ||
import dva, { connect } from 'dva'; | ||
import { Route } from 'dva/router'; | ||
|
||
const app = dva(); | ||
|
||
app.model({ | ||
namespace: 'count', | ||
state: 0, | ||
reducers: { | ||
['count/add' ](count) { return count + 1 }, | ||
['count/minus'](count) { return count - 1 }, | ||
}, | ||
}); | ||
|
||
const Count = ({ count, dispatch }) => | ||
<div> | ||
<h2>{ count }</h2> | ||
<button key="add" onClick={() => { dispatch({type: 'count/add'})}}>+</button> | ||
<button key="minus" onClick={() => { dispatch({type: 'count/minus'})}}>-</button> | ||
</div> | ||
|
||
const HomePage = connect(({ count }) => ({ count }))(Count); | ||
|
||
app.router( | ||
<Route path="/" component={HomePage} /> | ||
); | ||
|
||
app.start('root'); | ||
``` | ||
|
||
## More examples | ||
|
||
- [count](./examples/count) | ||
- [popular-products](./examples/popular-products) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('redux-saga/effects'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Demo</title> | ||
<link rel="stylesheet" href="index.css" /> | ||
</head> | ||
<body> | ||
|
||
<div id="root"></div> | ||
|
||
<script src="common.js"></script> | ||
<script src="index.js"></script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import dva, { connect } from 'dva'; | ||
import { Route } from 'dva/router'; | ||
|
||
const app = dva(); | ||
|
||
app.model({ | ||
namespace: 'count', | ||
state: 0, | ||
reducers: { | ||
['count/add' ](count) { return count + 1 }, | ||
['count/minus'](count) { return count - 1 }, | ||
}, | ||
}); | ||
|
||
const Count = ({ count, dispatch }) => | ||
<div> | ||
<h2>{ count }</h2> | ||
<button key="add" onClick={() => { dispatch({type: 'count/add'})}}>+</button> | ||
<button key="minus" onClick={() => { dispatch({type: 'count/minus'})}}>-</button> | ||
</div> | ||
|
||
const HomePage = connect(({ count }) => ({ count }))(Count); | ||
|
||
app.router( | ||
<Route path="/" component={HomePage} /> | ||
); | ||
|
||
app.start('root'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"entry": { | ||
"index": "./index.js" | ||
}, | ||
"dependencies": { | ||
"dva": "*", | ||
"babel-polyfill": "^6.9.1", | ||
"react": "^15.1.0", | ||
"react-dom": "^15.1.0" | ||
}, | ||
"devDependencies": { | ||
"atool-build": "^0.7.6", | ||
"dora": "0.3.x", | ||
"dora-plugin-proxy": "^0.7.0", | ||
"dora-plugin-webpack": "0.6.x", | ||
"dora-plugin-webpack-hmr": "^0.1.0" | ||
}, | ||
"scripts": { | ||
"start": "dora --plugins \"proxy,webpack?disableNpmInstall,webpack-hmr\"" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Demo</title> | ||
<link rel="stylesheet" href="index.css" /> | ||
</head> | ||
<body> | ||
|
||
<div id="root"></div> | ||
|
||
<script src="common.js"></script> | ||
<script src="index.js"></script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import "babel-polyfill"; | ||
import React from 'react'; | ||
import dva, { connect } from 'dva'; | ||
import { put, call } from 'dva/effects'; | ||
import { Route } from 'dva/router'; | ||
|
||
const app = dva(); | ||
|
||
app.model({ | ||
namespace: 'products', | ||
state: { | ||
list: [], | ||
loading: false, | ||
}, | ||
subscriptions: [ | ||
function(dispatch) { | ||
dispatch({type: 'products/query'}); | ||
}, | ||
], | ||
effects: { | ||
['products/query']: function*() { | ||
yield call(delay(800)); | ||
yield put({ | ||
type: 'products/query/success', | ||
payload: ['ant-tool', 'roof'], | ||
}); | ||
}, | ||
}, | ||
reducers: { | ||
['products/query'](state) { | ||
return { ...state, loading: true, }; | ||
}, | ||
['products/query/success'](state, { payload }) { | ||
return { ...state, loading: false, list: payload }; | ||
}, | ||
}, | ||
}); | ||
|
||
const MainView = connect(({products}) => ({products}))(ProductList); | ||
|
||
app.router( | ||
<Route path="/" component={MainView} /> | ||
); | ||
|
||
app.start('root'); | ||
|
||
/////////////////// | ||
// Utils | ||
|
||
function delay(timeout) { | ||
return () => { | ||
return new Promise(resolve => { | ||
setTimeout(resolve, timeout); | ||
}); | ||
}; | ||
} | ||
|
||
/////////////////// | ||
// Components | ||
|
||
function ProductList(props) { | ||
return ( | ||
<div> | ||
<h2>Popular Products</h2> | ||
{ | ||
props.products.loading ? 'loading' : | ||
props.products.list.map((product, index) => ( | ||
<li key={index}>{product}</li> | ||
)) | ||
} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"entry": { | ||
"index": "./index.js" | ||
}, | ||
"dependencies": { | ||
"babel-polyfill": "^6.9.1", | ||
"react": "^15.1.0", | ||
"react-dom": "^15.1.0" | ||
}, | ||
"devDependencies": { | ||
"atool-build": "^0.7.6", | ||
"dora": "0.3.x", | ||
"dora-plugin-proxy": "^0.7.0", | ||
"dora-plugin-webpack": "0.6.x", | ||
"dora-plugin-webpack-hmr": "^0.1.0" | ||
}, | ||
"scripts": { | ||
"start": "dora --plugins \"proxy,webpack?disableNpmInstall,webpack-hmr\"" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"name": "dva", | ||
"version": "0.0.1", | ||
"description": "Front-end framework based on react, redux, react-redux, react-router and redux-saga, inspired by elm and choo.", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/sorrycc/dva" | ||
}, | ||
"homepage": "https://github.com/sorrycc/dva", | ||
"main": "lib/index.js", | ||
"author": "chencheng <sorrycc@gmail.com>", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "rm -rf lib && babel src --out-dir lib --ignore __tests__", | ||
"lint": "eslint --ext .js src" | ||
}, | ||
"dependencies": { | ||
"react-redux": "4.4.x", | ||
"react-router": "^2.4.1", | ||
"react-router-redux": "^4.0.5", | ||
"redux": "^3.5.2", | ||
"redux-actions": "^0.10.0", | ||
"redux-saga": "^0.10.5" | ||
}, | ||
"peerDependencies": { | ||
"react": "^15.1.0", | ||
"react-dom": "^15.1.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "6.6.x", | ||
"babel-eslint": "^6.0.4", | ||
"babel-plugin-add-module-exports": "~0.1.2", | ||
"babel-plugin-transform-runtime": "^6.9.0", | ||
"babel-preset-es2015": "~6.6.0", | ||
"babel-preset-react": "^6.5.0", | ||
"babel-preset-stage-0": "~6.5.0", | ||
"babel-runtime": "^6.9.2", | ||
"eslint": "^2.7.0", | ||
"eslint-config-airbnb": "^6.2.0" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"es2015", | ||
"react", | ||
"stage-0" | ||
], | ||
"plugins": [ | ||
"add-module-exports", | ||
"transform-runtime" | ||
] | ||
}, | ||
"pre-commit": [ | ||
"lint" | ||
], | ||
"files": [ | ||
"lib", | ||
"src" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('react-router'); |
Oops, something went wrong.