Comparing version 0.0.2 to 0.0.3
@@ -12,2 +12,6 @@ 'use strict'; | ||
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
@@ -109,17 +113,51 @@ | ||
function getWatcher(k, saga) { | ||
return _regenerator2.default.mark(function _callee() { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return (0, _reduxSaga.takeLatest)(k, saga); | ||
var _saga = saga; | ||
var _type = 'takeEvery'; | ||
if (Array.isArray(saga)) { | ||
var _saga2 = (0, _slicedToArray3.default)(saga, 2); | ||
case 2: | ||
case 'end': | ||
return _context.stop(); | ||
_saga = _saga2[0]; | ||
opts = _saga2[1]; | ||
opts = opts || {}; | ||
(0, _utils.check)(opts.type, _utils.is.sagaType, 'Type must be takeEvery or takeLatest'); | ||
(0, _utils.warn)(opts.type, function (v) { | ||
return v === 'takeLatest'; | ||
}, 'takeEvery is the default type, no need to set it by opts'); | ||
_type = opts.type; | ||
} | ||
if (_type === 'takeEvery') { | ||
return _regenerator2.default.mark(function _callee() { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return (0, _reduxSaga.takeEvery)(k, _saga); | ||
case 2: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
} | ||
}, _callee, this); | ||
}); | ||
}, _callee, this); | ||
}); | ||
} else { | ||
return _regenerator2.default.mark(function _callee2() { | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return (0, _reduxSaga.takeLatest)(k, _saga); | ||
case 2: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
}); | ||
} | ||
} | ||
@@ -129,18 +167,18 @@ | ||
var k, watcher; | ||
return _regenerator2.default.wrap(function rootSaga$(_context2) { | ||
return _regenerator2.default.wrap(function rootSaga$(_context3) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context2.t0 = _regenerator2.default.keys(sagas); | ||
_context3.t0 = _regenerator2.default.keys(sagas); | ||
case 1: | ||
if ((_context2.t1 = _context2.t0()).done) { | ||
_context2.next = 9; | ||
if ((_context3.t1 = _context3.t0()).done) { | ||
_context3.next = 9; | ||
break; | ||
} | ||
k = _context2.t1.value; | ||
k = _context3.t1.value; | ||
if (!sagas.hasOwnProperty(k)) { | ||
_context2.next = 7; | ||
_context3.next = 7; | ||
break; | ||
@@ -150,7 +188,7 @@ } | ||
watcher = getWatcher(k, sagas[k]); | ||
_context2.next = 7; | ||
_context3.next = 7; | ||
return (0, _effects.fork)(watcher); | ||
case 7: | ||
_context2.next = 1; | ||
_context3.next = 1; | ||
break; | ||
@@ -160,3 +198,3 @@ | ||
case 'end': | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
@@ -163,0 +201,0 @@ } |
@@ -7,2 +7,3 @@ 'use strict'; | ||
exports.check = check; | ||
exports.warn = warn; | ||
exports.log = log; | ||
@@ -16,2 +17,8 @@ function check(value, predicate, error) { | ||
function warn(value, predicate, error) { | ||
if (!predicate(value)) { | ||
log('warn', 'uncaught at check', error); | ||
} | ||
} | ||
var is = exports.is = { | ||
@@ -36,2 +43,5 @@ undef: function undef(v) { | ||
return v && v.$$typeof && v.$$typeof.toString() === 'Symbol(react.element)'; | ||
}, | ||
sagaType: function sagaType(v) { | ||
return v === 'takeEvery' || v === 'takeLatest'; | ||
} | ||
@@ -38,0 +48,0 @@ }; |
{ | ||
"name": "dva", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Front-end framework based on react, redux, react-redux, react-router and redux-saga, inspired by elm and choo.", | ||
@@ -10,2 +10,13 @@ "repository": { | ||
"homepage": "https://github.com/sorrycc/dva", | ||
"keywords": [ | ||
"dva", | ||
"ant", | ||
"react", | ||
"redux", | ||
"redux-saga", | ||
"elm", | ||
"choo", | ||
"framework", | ||
"frontend" | ||
], | ||
"main": "lib/index.js", | ||
@@ -12,0 +23,0 @@ "author": "chencheng <sorrycc@gmail.com>", |
@@ -9,4 +9,10 @@ # dva | ||
## Quick start with count | ||
## Documents | ||
- [dva 简介](https://github.com/sorrycc/dva/issues/1) | ||
## Quick Start | ||
Let's create an count app that changes when user click the + or - button. | ||
```javascript | ||
@@ -17,4 +23,6 @@ import React from 'react'; | ||
// 1. Initialize | ||
const app = dva(); | ||
// 2. Model | ||
app.model({ | ||
@@ -29,22 +37,32 @@ namespace: 'count', | ||
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> | ||
// 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> | ||
); | ||
}); | ||
const HomePage = connect(({ count }) => ({ count }))(Count); | ||
// 4. Router | ||
app.router( | ||
<Route path="/" component={HomePage} /> | ||
<Route path="/" component={App} /> | ||
); | ||
// 5. Start | ||
app.start('root'); | ||
``` | ||
## More examples | ||
## Examples | ||
- [count](./examples/count) | ||
- [popular-products](./examples/popular-products) | ||
- [Count](./examples/count) | ||
- [Popular Products](./examples/popular-products) | ||
- [Friend List](./examples/friend-list) | ||
## License | ||
[MIT](https://tldrlegal.com/license/mit-license) |
@@ -10,3 +10,3 @@ import React from 'react'; | ||
import { fork } from 'redux-saga/effects'; | ||
import { is, check } from './utils'; | ||
import { is, check, warn } from './utils'; | ||
@@ -67,5 +67,21 @@ function dva() { | ||
function getWatcher(k, saga) { | ||
return function*() { | ||
yield takeLatest(k, saga); | ||
}; | ||
let _saga = saga; | ||
let _type = 'takeEvery'; | ||
if (Array.isArray(saga)) { | ||
[_saga, opts] = saga; | ||
opts = opts || {}; | ||
check(opts.type, is.sagaType, 'Type must be takeEvery or takeLatest'); | ||
warn(opts.type, v => v === 'takeLatest', 'takeEvery is the default type, no need to set it by opts'); | ||
_type = opts.type; | ||
} | ||
if (_type === 'takeEvery') { | ||
return function*() { | ||
yield takeEvery(k, _saga); | ||
}; | ||
} else { | ||
return function*() { | ||
yield takeLatest(k, _saga); | ||
}; | ||
} | ||
} | ||
@@ -72,0 +88,0 @@ |
export function check(value, predicate, error) { | ||
if(!predicate(value)) { | ||
log('error', 'uncaught at check', error) | ||
log('error', 'uncaught at check', error); | ||
throw new Error(error) | ||
@@ -9,2 +9,8 @@ } | ||
export function warn(value, predicate, error) { | ||
if(!predicate(value)) { | ||
log('warn', 'uncaught at check', error); | ||
} | ||
} | ||
export const is = { | ||
@@ -18,2 +24,3 @@ undef : v => v === null || v === undefined, | ||
jsx : v => v && v.$$typeof && v.$$typeof.toString() === 'Symbol(react.element)', | ||
sagaType : v => v === 'takeEvery' || v === 'takeLatest', | ||
}; | ||
@@ -20,0 +27,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14979
348
66