Skip to content
Permalink
Browse files

add @adobe/redux-saga-promise

  • Loading branch information
alanhg
alanhg committed Feb 2, 2020
1 parent cfe6d0b commit 52f7ef7a287a51407d00d89cc04f2cdf09ea8df8
Showing with 105 additions and 13 deletions.
  1. +1 −0 package.json
  2. +4 −0 src/actions/index.js
  3. +6 −8 src/components/saga-test/saga-test-page.jsx
  4. +8 −3 src/effects/sagas.js
  5. +4 −2 src/index.js
  6. +82 −0 yarn.lock
@@ -63,6 +63,7 @@
]
},
"dependencies": {
"@adobe/redux-saga-promise": "^1.0.0",
"@babel/core": "7.6.0",
"ag-grid-community": "^21.0.1",
"ag-grid-react": "^21.0.1",
@@ -1,3 +1,5 @@
import { createPromiseAction } from '@adobe/redux-saga-promise';

let nextTodoId = 0;
export const addTodo = text => ({
type: 'ADD_TODO',
@@ -53,6 +55,8 @@ export const fetchUserAction = (count) => ({
});


export const fetchUserAction2 = createPromiseAction('USER_FETCH', (count) => ({ count }));

export const updateUserAgeAction = () => ({
type: 'UPDATE_USER_AGE'
});
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { fetchUserAction, testSaga } from '../../actions';
import { fetchUserAction2, testSaga } from '../../actions';
import { connect } from 'react-redux';
import { fetchUser } from '../../effects/thunk';
import { Button } from 'antd';
@@ -14,10 +14,6 @@ class SagaTestPage extends Component {
<div style={{ fontSize: 28 }}>
SagaTest
{this.props.books.map(item => <h3 key={item.title}>{JSON.stringify(item)}</h3>)}
<div>
hello world-alan-2222
</div>

<div>
user info
</div>
@@ -29,8 +25,10 @@ class SagaTestPage extends Component {
);
}
getFetchUserAction() {
return this.props.fetchUserAction(++count);
async getFetchUserAction() {
const res = await this.props.fetchUserAction2(++count);
console.log(2);
return res;
}
}
@@ -43,7 +41,7 @@ const mapStateToProps = (state) => {
const mapDispatchToProps = {
testSaga,
fetchUserAction,
fetchUserAction2,
fetchUser
};
@@ -1,10 +1,11 @@
import { call } from 'redux-saga/effects';
import { getBadRequest, getUserInfo } from '../api';
import { takeLeading } from '@redux-saga/core/effects';
import { fetchUserAction2 } from '../actions';
import { resolvePromiseAction } from '@adobe/redux-saga-promise';

function* fetchUserEffects(action) {
const userInfo = (yield call(getUserInfo)).data;
window.location.hash = 'hello';
// yield put(setUserInfoAsync(userInfo));
// yield delay(1000);
//
@@ -17,7 +18,6 @@ function sayHello() {
}

function* testExceptionEffects() {
alert(1);
console.log('Class: testExceptionEffects, Function: testExceptionEffects, Line 18 1(): ', 1);
try {
yield call(getBadRequest);
@@ -26,9 +26,14 @@ function* testExceptionEffects() {
}
}

function* testExceptionEffects2(action) {
const userInfo = (yield call(getUserInfo)).data;
console.log(1);
yield call(resolvePromiseAction, action, userInfo);
}

function* mySaga() {
yield takeLeading('USER_FETCH', testExceptionEffects);
yield takeLeading(fetchUserAction2, testExceptionEffects2);
}

export default mySaga;
@@ -15,8 +15,10 @@ import 'ag-grid-community/dist/styles/ag-grid.css';
import 'ag-grid-community/dist/styles/ag-theme-balham.css';
import { safe } from './config/saga-middleware';
import Promise from 'promise/lib/es6-extensions.js';
window.Promise = Promise;
import './config/axios';
import { promiseMiddleware } from '@adobe/redux-saga-promise';

window.Promise = Promise;

const effectMiddleware = next => effect => {
if (effect.type === 'FORK') {
@@ -36,7 +38,7 @@ export const history = createBrowserHistory();

const reduxDevtools = window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__() : f => f;

const middleWares = [sagaMiddleware, thunk, routerMiddleware(history)];
const middleWares = [promiseMiddleware, sagaMiddleware, thunk, routerMiddleware(history)];

const store = createStore(rootReducer(history), compose(applyMiddleware(...middleWares), reduxDevtools));

@@ -2,6 +2,14 @@
# yarn lockfile v1


"@adobe/redux-saga-promise@^1.0.0":
version "1.0.0"
resolved "https://registry.npmjs.org/@adobe/redux-saga-promise/-/redux-saga-promise-1.0.0.tgz#cb52fc36ec2455b9cd962d4037d6eeea0951c93d"
dependencies:
lodash "^4.17.15"
redux-actions "^2.6.5"
redux-saga "^1.1.3"

"@ant-design/colors@^3.1.0":
version "3.2.2"
resolved "https://registry.npm.taobao.org/@ant-design/colors/download/@ant-design/colors-3.2.2.tgz#5ad43d619e911f3488ebac303d606e66a8423903"
@@ -1178,27 +1186,61 @@
redux "^4.0.4"
typescript-tuple "^2.2.1"

"@redux-saga/core@^1.1.3":
version "1.1.3"
resolved "https://registry.npmjs.org/@redux-saga/core/-/core-1.1.3.tgz#3085097b57a4ea8db5528d58673f20ce0950f6a4"
dependencies:
"@babel/runtime" "^7.6.3"
"@redux-saga/deferred" "^1.1.2"
"@redux-saga/delay-p" "^1.1.2"
"@redux-saga/is" "^1.1.2"
"@redux-saga/symbols" "^1.1.2"
"@redux-saga/types" "^1.1.0"
redux "^4.0.4"
typescript-tuple "^2.2.1"

"@redux-saga/deferred@^1.1.0":
version "1.1.0"
resolved "https://registry.npm.taobao.org/@redux-saga/deferred/download/@redux-saga/deferred-1.1.0.tgz#aff018f64a936c288c18bd64ddf9ccfa143db6b4"

"@redux-saga/deferred@^1.1.2":
version "1.1.2"
resolved "https://registry.npmjs.org/@redux-saga/deferred/-/deferred-1.1.2.tgz#59937a0eba71fff289f1310233bc518117a71888"

"@redux-saga/delay-p@^1.1.0":
version "1.1.0"
resolved "https://registry.npm.taobao.org/@redux-saga/delay-p/download/@redux-saga/delay-p-1.1.0.tgz#4024f979d0f78763d2e90233be8c922781ae4400"
dependencies:
"@redux-saga/symbols" "^1.1.0"

"@redux-saga/delay-p@^1.1.2":
version "1.1.2"
resolved "https://registry.npmjs.org/@redux-saga/delay-p/-/delay-p-1.1.2.tgz#8f515f4b009b05b02a37a7c3d0ca9ddc157bb355"
dependencies:
"@redux-saga/symbols" "^1.1.2"

"@redux-saga/is@^1.1.0":
version "1.1.0"
resolved "https://registry.npm.taobao.org/@redux-saga/is/download/@redux-saga/is-1.1.0.tgz#d74358364ebde160bf1b8bd94903ff7684b12d41"
dependencies:
"@redux-saga/symbols" "^1.1.0"
"@redux-saga/types" "^1.1.0"

"@redux-saga/is@^1.1.2":
version "1.1.2"
resolved "https://registry.npmjs.org/@redux-saga/is/-/is-1.1.2.tgz#ae6c8421f58fcba80faf7cadb7d65b303b97e58e"
dependencies:
"@redux-saga/symbols" "^1.1.2"
"@redux-saga/types" "^1.1.0"

"@redux-saga/symbols@^1.1.0":
version "1.1.0"
resolved "https://registry.npm.taobao.org/@redux-saga/symbols/download/@redux-saga/symbols-1.1.0.tgz#676b277cb5deb48ce723b2b394cbae97f82e8319"

"@redux-saga/symbols@^1.1.2":
version "1.1.2"
resolved "https://registry.npmjs.org/@redux-saga/symbols/-/symbols-1.1.2.tgz#216a672a487fc256872b8034835afc22a2d0595d"

"@redux-saga/types@^1.1.0":
version "1.1.0"
resolved "https://registry.npm.taobao.org/@redux-saga/types/download/@redux-saga/types-1.1.0.tgz#0e81ce56b4883b4b2a3001ebe1ab298b84237204"
@@ -7843,6 +7885,10 @@ jszip@^3.1.5:
readable-stream "~2.3.6"
set-immediate-shim "~1.0.1"

just-curry-it@^3.1.0:
version "3.1.0"
resolved "https://registry.npmjs.org/just-curry-it/-/just-curry-it-3.1.0.tgz#ab59daed308a58b847ada166edd0a2d40766fbc5"

killable@^1.0.0:
version "1.0.1"
resolved "https://registry.npm.taobao.org/killable/download/killable-1.0.1.tgz#4c8ce441187a061c7474fb87ca08e2a638194892"
@@ -11308,12 +11354,32 @@ reduce-function-call@^1.0.1:
dependencies:
balanced-match "^1.0.0"

reduce-reducers@^0.4.3:
version "0.4.3"
resolved "https://registry.npmjs.org/reduce-reducers/-/reduce-reducers-0.4.3.tgz#8e052618801cd8fc2714b4915adaa8937eb6d66c"

redux-actions@^2.6.5:
version "2.6.5"
resolved "https://registry.npmjs.org/redux-actions/-/redux-actions-2.6.5.tgz#bdca548768ee99832a63910c276def85e821a27e"
dependencies:
invariant "^2.2.4"
just-curry-it "^3.1.0"
loose-envify "^1.4.0"
reduce-reducers "^0.4.3"
to-camel-case "^1.0.0"

redux-saga@1.0.5:
version "1.0.5"
resolved "https://registry.npm.taobao.org/redux-saga/download/redux-saga-1.0.5.tgz#03317261bc5fa7ee2ecb778f4e4848f573557bbb"
dependencies:
"@redux-saga/core" "^1.0.3"

redux-saga@^1.1.3:
version "1.1.3"
resolved "https://registry.npmjs.org/redux-saga/-/redux-saga-1.1.3.tgz#9f3e6aebd3c994bbc0f6901a625f9a42b51d1112"
dependencies:
"@redux-saga/core" "^1.1.3"

redux-thunk@^2.3.0:
version "2.3.0"
resolved "https://registry.npm.taobao.org/redux-thunk/download/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"
@@ -13068,6 +13134,12 @@ to-buffer@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz#493bd48f62d7c43fcded313a03dcadb2e1213a80"

to-camel-case@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/to-camel-case/-/to-camel-case-1.0.0.tgz#1a56054b2f9d696298ce66a60897322b6f423e46"
dependencies:
to-space-case "^1.0.0"

to-fast-properties@^1.0.3:
version "1.0.3"
resolved "https://registry.npm.taobao.org/to-fast-properties/download/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"
@@ -13076,6 +13148,10 @@ to-fast-properties@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"

to-no-case@^1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/to-no-case/-/to-no-case-1.0.2.tgz#c722907164ef6b178132c8e69930212d1b4aa16a"

to-object-path@^0.3.0:
version "0.3.0"
resolved "https://registry.npm.taobao.org/to-object-path/download/to-object-path-0.3.0.tgz#297588b7b0e7e0ac08e04e672f85c1f4999e17af"
@@ -13104,6 +13180,12 @@ to-regex@^3.0.1, to-regex@^3.0.2:
regex-not "^1.0.2"
safe-regex "^1.1.0"

to-space-case@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/to-space-case/-/to-space-case-1.0.0.tgz#b052daafb1b2b29dc770cea0163e5ec0ebc9fc17"
dependencies:
to-no-case "^1.0.0"

toggle-selection@^1.0.6:
version "1.0.6"
resolved "https://registry.npm.taobao.org/toggle-selection/download/toggle-selection-1.0.6.tgz#6e45b1263f2017fa0acc7d89d78b15b8bf77da32"

0 comments on commit 52f7ef7

Please sign in to comment.
You can’t perform that action at this time.