Skip to content

Commit 6b42856

Browse files
author
Z-wave
committed
saga
1 parent 43118dc commit 6b42856

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

src/redux/actionCreator/index.jsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
export default {
2+
testData: (data) => {
3+
return {
4+
type: 'GET_START',
5+
params:data
6+
}
7+
},
28
getIndexData: (data) => {
3-
console.log(11111);
49
return {
510
type: 'GET_INDEXLIST',
611
params:data

src/redux/reducers/index.jsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
export default (state = [], action) => {
2-
console.log(3333);
1+
export default (state, action) => {
2+
console.log(action);
33
switch(action.type) {
44
case 'GET_START':
55
return {indexList:[], status: 'GET_START' }
66
case "GET_INDEXLIST":
7-
if(action.more){
7+
let {params={}} = action
8+
if(params.more){
89
let arr = [...state,...action.data]
910
return {indexList:arr, status: 'LOADING_STATE' }
1011
}else{

src/redux/sagas/index.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { put, takeEvery } from 'redux-saga/effects'
22
import axios from 'axios'
33

44
function* getIndexData(params) {
5-
console.log(params);
65
try {
7-
const res = yield axios.get('/v1/topics',{params:params})
6+
const res = yield axios.get('/v1/topics',{params:params.params})
87

98
if(res.status == 200){
109
yield put({
1110
type: "GET_INDEXLIST",
12-
data: res.data.data
11+
data: res.data.data,
12+
params:params.params
1313
});
1414
}
1515
}catch(e){
@@ -19,5 +19,5 @@ function* getIndexData(params) {
1919
}
2020

2121
export default function* fecthData() {
22-
yield takeEvery("GET_INDEXLIST", getIndexData)
22+
yield takeEvery("GET_START", getIndexData)
2323
}

src/utils/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ global.delcookie = function(name){
2727
if(cval!=null) document.cookie= name + "="+cval+"; path=/;expires="+exp.toGMTString();
2828
}
2929

30-
global.isScrolling = function(){
30+
global.isBottom = function(){
3131
const { scrollTop } = document.documentElement || document.body
3232
const { clientHeight, scrollHeight } = document.documentElement;
3333

src/views/index/index.jsx

+11-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class App extends React.Component {
2121
componentDidMount() {
2222
let { dispatch,match } = this.props
2323

24-
dispatch(actionCreator.getIndexData(this.params));
24+
dispatch(actionCreator.testData(this.params));
2525
setInterval(()=>{
2626
this.halderScroll()
2727
},1000)
@@ -35,27 +35,32 @@ class App extends React.Component {
3535
this.params.tab = tab
3636
this.params.page = 1
3737
this.params.more = false
38-
dispatch(actionCreator.getIndexData(this.params));
38+
dispatch(actionCreator.testData(this.params));
3939
}else{
40-
this.isLoad = true
40+
setTimeout(() => {
41+
this.isLoad = true
42+
}, 2000);
4143
}
4244

4345
}
4446

4547

4648
halderScroll(){
4749
let { dispatch } = this.props
50+
let timer = null
4851

49-
if(isScrolling() && this.isLoad){
52+
53+
if(isBottom() && this.isLoad){
54+
console.log(1111);
5055
this.params.more = true
5156
this.params.page++
52-
dispatch(actionCreator.getIndexData(this.params));
57+
dispatch(actionCreator.testData(this.params));
5358
this.isLoad = false
5459
}
60+
5561
}
5662

5763
render() {
58-
console.log(this.props);
5964
let {indexList = []} = this.props
6065

6166
return (

0 commit comments

Comments
 (0)