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-subscriptions的更多相关文章

  1. dva + antd + mockjs 实现基础用户管理

    1.安装dva-cli npm install dva-cli -g 2.创建应用 dva new dvadashboard   [dvadashboard为项目名]       3.安装mockjs ...

  2. dva.js 用法详解:列表展示

    本教程案例github:https://github.com/axel10/dva_demo-Counter-and-list/tree/master 这次主要通过在线获取用户数据并且渲染成列表这个案 ...

  3. React框架 dva 和 mobx 的使用感受

    最近在用react写web项目,领导为了让前端便于维护要求都用react作为开发基础,框架选型不限.在使用 react 的时候或多或少会接触到状态管理,从开始学 react 到现在也挺久了,做一些前端 ...

  4. dva.js 上手

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

  5. dva,清除模块数据

    前言: 在项目中,模块过多,dva使用namespace分离模块后,若没有在模块卸载后清除对应的数据,下次进入时,有可能会有上一次数据的残留. 比如详情页,从A商品的详情页离开后,返回选择B商品进入, ...

  6. dva 知识点

    dva中,路由模式从hashHistory换成 browserHistory: dva-cli创建的项目中,src/index.js相应部分修改如下: import browserHistory fr ...

  7. 003-and design-dva.js 知识导图-02-Reducer,Effect,Subscription,Router,dva配置,工具

    一.Reducer reducer 是一个函数,接受 state 和 action,返回老的或新的 state .即:(state, action) => state 增删改 以 todos 为 ...

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

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

  9. dva subscription的使用方法

    import { routerRedux } from 'dva/router' export default { namespace: 'notice', state: { notices:[], ...

  10. Vuex、Flux、Redux、Redux-saga、Dva、MobX

    https://www.jqhtml.com/23003.html 这篇文章试着聊明白这一堆看起来挺复杂的东西.在聊之前,大家要始终记得一句话:一切前端概念,都是纸老虎. 不管是Vue,还是 Reac ...

随机推荐

  1. IPC远程入侵

    https://mp.weixin.qq.com/s/rQxvp2Sq8E4pBn-E9-COww IPC远程入侵 黑客网络技术 4月19日 一.什么是IPC 进程间通信(IPC,Inter-Proc ...

  2. Android:高通平台性能调试

    1.GPU / CPU 信息打印脚本 gpu_cpu_info.bat @echo off echo "==================GPU====================== ...

  3. C之数组

    1. 数组的地址就是数组里元素的首地址 2. 数组其实就是一块连续的内存空间 3. 每个元素所占大小取决于数组的类型 4. 所有指针变量在内存中的长度是一样的

  4. 17. dashboard

    17. dashboard dashboard的安装步骤: wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-bet ...

  5. nodejs连接mongodb(密码)

    const MongoClient = require('mongodb').MongoClient; const url = 'mongodb://user:password@localhost:2 ...

  6. Python扫描器-爬虫基础

    0x1.基础框架原理 1.1.爬虫基础 爬虫程序主要原理就是模拟浏览器发送请求->下载网页代码->只提取有用的数据->存放于数据库或文件中 1.1.基础原理 1.发起HTTP请求 2 ...

  7. 嵌入(embedding)层的理解

    首先,我们有一个one-hot编码的概念. 假设,我们中文,一共只有10个字...只是假设啊,那么我们用0-9就可以表示完 比如,这十个字就是“我从哪里来,要到何处去” 其分别对应“0-9”,如下: ...

  8. web框架初阶

    第一站 文件结构:web--- |--home.py #页面处理函数    |--index.py #主体函数 |--indexPlus.py #主体函数加强版 |--webdaem.py #通过we ...

  9. npm install, npm install -g, npm install --save, npm install --save-dev之间的区别

    1.npm install X 安装X到项目的node_modules文件夹 会修改package.json,在dependencies中写入依赖.(关于这一点,网上的大部分文章都是说,不会修改pac ...

  10. 《深入理解计算机系统》☞hello world背后的故事

    一步到位的hello world 首先一个简单的C语言版本的hello world例子,保存在文件hello.c中. #include <stdio.h> int main() { pri ...