zoukankan      html  css  js  c++  java
  • DVA-subscriptions

    import { routerRedux } from 'dva/router'
    export default {
      namespace: 'notice',
      state: {
        notices:[],
        loading: false,
        editModalVisible: false
      },
      effects: {
        *watchAndRefreshList({ dispatch }, { put, call, take }){
          let listAction = {};
        //关闭弹框后重新获取数据
        //调用hideModal就会触发fetch
    
          while(true){
            const action = yield take(['notice/fetch', 'notice/hideModal']);
            console.log('action', action);
            if(action.type == 'notice/fetch'){
              action.type = 'fetch';
              listAction = action;
            }
            if(action.type == 'notice/hideModal'){
              action.type = 'hideModal';
              dispatch(listAction);
            }
          }
        },
        *fetch({ payload }, { call, put }) {
          const response = yield call(Get, '/api/notices');
          yield put({
            type: 'save',
            payload: response
          })
        },
        *gologin({ payload }, { call, put }) {
          yield put(routerRedux.push('/user/login'))
        }
      },
      reducers: {
        save(state, action) {
          return {
            ...state,
            notices: action.payload
          }
        },
        showModal(state, action){
          return {
            ...state,
            editModalVisible: true
          }
        },
        hideModal(state, action){
          return {
            ...state,
            editModalVisible: false,
          }
        },
      },
      subscriptions: {
        //监听地址,如果地址含有app则跳转到登陆页
        setup({ dispatch, history }) {
          history.listen(location => {
            if (location.pathname.includes('app')) {
              dispatch({
                type: 'gologin'
              })
            }
          });
        },
        watchAndRefreshList({ dispatch, history }){
          dispatch({
            type: 'watchAndRefreshList',
            dispatch
          });
        }
      },
    };
  • 相关阅读:
    2017《Java技术》预备作业 计科1501 杨欣蕊
    Java技术预备作业02杨欣蕊
    系统无法从光盘启动
    动态数组ArrayList的使用
    dbgrid数据显示和数据源不同
    异步任务判断服务器是否开启
    Java字符串格式化
    思科2960 监听端口设置
    64位win7安装jdk和eclipse
    Delphi临界区的使用
  • 原文地址:https://www.cnblogs.com/zoeeying/p/11093311.html
Copyright © 2011-2022 走看看