Преглед изворни кода

Unlimited list to add a special method (#451)

陈帅 пре 8 година
родитељ
комит
69a9d9bb3a
2 измењених фајлова са 22 додато и 1 уклоњено
  1. 21 0
      src/models/list.js
  2. 1 1
      src/routes/List/SearchList.js

+ 21 - 0
src/models/list.js

@@ -16,6 +16,21 @@ export default {
       });
       const response = yield call(queryFakeList, payload);
       yield put({
+        type: 'queryList',
+        payload: Array.isArray(response) ? response : [],
+      });
+      yield put({
+        type: 'changeLoading',
+        payload: false,
+      });
+    },
+    *appendFetch({ payload }, { call, put }) {
+      yield put({
+        type: 'changeLoading',
+        payload: true,
+      });
+      const response = yield call(queryFakeList, payload);
+      yield put({
         type: 'appendList',
         payload: Array.isArray(response) ? response : [],
       });
@@ -27,6 +42,12 @@ export default {
   },
 
   reducers: {
+    queryList(state, action) {
+      return {
+        ...state,
+        list: action.payload,
+      };
+    },
     appendList(state, action) {
       return {
         ...state,

+ 1 - 1
src/routes/List/SearchList.js

@@ -32,7 +32,7 @@ export default class SearchList extends Component {
 
   fetchMore = () => {
     this.props.dispatch({
-      type: 'list/fetch',
+      type: 'list/appendFetch',
       payload: {
         count: pageSize,
       },