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
});
}
},
};

dva subscription的使用方法的更多相关文章

  1. 使用dva框架的总结

    最近的项目是react+dva+atd+webpack的一个后台项目,刚接触dva就感觉很喜欢,很简洁用着很爽. 关于使用redux中的一些问题 1.文件切换问题. redux的项目通常哟啊分为red ...

  2. dva.js 上手

    来源:https://pengtikui.cn/dva.js-get-started/ ——------------------------------------------------------ ...

  3. 002-and design-基于dva的基本项目搭建

    一.概述 在真实项目开发中,你可能会需要 Redux 或者 MobX 这样的数据应用框架,Ant Design React 作为一个 UI 库,可以和任何 React 生态圈内的应用框架搭配使用.我们 ...

  4. React-Native集成dva.js

    dvajs作为一个基于redux的状态管理框架,在react中的表现还是很不错的,如果我们想要在react-native应用中使用dvajs该怎么做呢? 首先安装dva-core和react-redu ...

  5. DvaJS入门课

    不管是Vue还是React,他们都没解决组件间的通信和数据流问题.当然,这个说法不是很准确,准确的说法是他们都没很好的处理这些问题.我们是可以用一些烂手段去解决这个问题,但是当应用比较大.数据多的时候 ...

  6. Android Weekly Notes Issue #223

    Android Weekly Issue #223 September 18th, 2016 Android Weekly Issue #223 本期内容包括: Offline时间戳处理; Acces ...

  7. EventBus源码解析 源码阅读记录

    EventBus源码阅读记录 repo地址: greenrobot/EventBus EventBus的构造 双重加锁的单例. static volatile EventBus defaultInst ...

  8. RxJava 与 Retrofit 结合的最佳实践

    转自:http://gank.io/post/56e80c2c677659311bed9841?from=timeline&isappinstalled=0&nsukey=g1D1Y6 ...

  9. POST请求中参数以form data和request payload形式+清空数组方式

    测试与服务端ajax时用的dva封装的request方法,而后端怎么也拿不到参数.结果返现参数在request payload里. HTTP POST表单请求提交时:Content-Typeappli ...

随机推荐

  1. Android数据存储之SQLite 数据库学习

    Android提供了五种存取数据的方式 (1)SharedPreference,存放较少的五种类型的数据,只能在同一个包内使用,生成XML的格式存放在设备中 (2) SQLite数据库,存放各种数据, ...

  2. Windows使用filezilla搭建FTP服务器

    参考:https://segmentfault.com/a/1190000009033181 下载软件https://filezilla-project.org/ 安装过程不详述,默认安装即可 启动软 ...

  3. python设置redis过期时间

    import time import redis if __name__ == "__main__": try: conn=redis.StrictRedis(host='192. ...

  4. [转载]ODBC数据源

    在做java数据库连接的时候遇到了点问题. 首先是创建数据源时,odbc里没有要用的驱动,因为我是64位的系统,但是安装的是32位的office..于是去C/windows/syswow64文件夹下, ...

  5. python技巧总结之set、日志、rsa加密

    一.日志模块logging模块调用 1.日志模块使用原理 #!/usr/bin/python # -*- coding:utf-8 -*- import logging # 方式一: "&q ...

  6. [py]python中__new__作用

    元类metaclass 使劲搞,但是没搞清楚__new__的作用 了解Python元类 Python进阶:一步步理解Python中的元类metaclass Python中的__new__和__init ...

  7. (转)Springboot+shiro配置笔记+错误小结

    springboot不像springmvc,它没有xml配置文件,那该如何配置shiro呢,其实也不难,用java代码+注解来解决这个问题.仅以此篇记录我对shiro的学习,如有对过客造成不便,实在抱 ...

  8. samba文件共享服务配置一(共2节)

    一.samba服务简介 Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.SMB(Server Messages Block,信息服务块)是一种在局域网上 ...

  9. 站点默认访问https

    需求简介 现在网站都是https访问了,再用http会显得很low,所以我要把网站设置为默认的https访问. 1nginx的rewrite方法 这应该是大家最容易想到的方法,将所有的http请求通过 ...

  10. leetcode 数据库题解

    184. Department Highest Salary 题意: The Employee table holds all employees. Every employee has an Id, ...