Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Jun 24, 2016
0 parents commit 7f38785
Show file tree
Hide file tree
Showing 17 changed files with 469 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
tmp
node_modules
lib
7 changes: 7 additions & 0 deletions .jshintignore
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
32 changes: 32 additions & 0 deletions .jshintrc
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
}
}
7 changes: 7 additions & 0 deletions Makefile
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
47 changes: 47 additions & 0 deletions README.md
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)

1 change: 1 addition & 0 deletions effects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('redux-saga/effects');
16 changes: 16 additions & 0 deletions examples/count/index.html
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>
29 changes: 29 additions & 0 deletions examples/count/index.js
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');
21 changes: 21 additions & 0 deletions examples/count/package.json
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\""
}
}
16 changes: 16 additions & 0 deletions examples/popular-products/index.html
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>
73 changes: 73 additions & 0 deletions examples/popular-products/index.js
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>
);
}
20 changes: 20 additions & 0 deletions examples/popular-products/package.json
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\""
}
}
59 changes: 59 additions & 0 deletions package.json
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"
]
}
1 change: 1 addition & 0 deletions router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('react-router');
Loading

0 comments on commit 7f38785

Please sign in to comment.