Guest User

Untitled

a guest
Apr 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. import * as types from '../constants/ActionsTypes'
  2.  
  3. let initialState = {
  4. city: '',
  5. weather: [],
  6. loadMore: 5
  7. };
  8.  
  9. const weather = (state = initialState, action) => {
  10. switch (action.type) {
  11. case types.ADD_WEATHER:
  12. return Object.assign({}, state, {
  13. city: action.cityName,
  14. weather: [
  15. ...action.cityWeather
  16. ],
  17. loadMore: 5
  18. });
  19. default:
  20. return state;
  21. }
  22. }
  23.  
  24. export default weather;
  25.  
  26. import * as types from '../constants/ActionsTypes'
  27.  
  28. let initialState = {
  29. city: '',
  30. weather: [],
  31. loadMore: 5
  32. };
  33.  
  34. const loadMore = (state = initialState, action) => {
  35. switch (action.type) {
  36. case types.LOAD_MORE:
  37. return Object.assign({}, state, {
  38. ...state, // when I click 'load more' the state is empty
  39. loadMore: action.loadMore
  40. });
  41. default:
  42. return state;
  43. }
  44. }
  45.  
  46. export default loadMore;
  47.  
  48. import * as types from '../constants/ActionsTypes'
  49. import { combineReducers } from 'redux';
  50. import weather from './addWeather';
  51. import loadMore from './loadMore';
  52.  
  53. const reducers = combineReducers({
  54. weather,
  55. loadMore
  56. });
  57.  
  58. export default reducers;
  59.  
  60. import React, { Component } from 'react';
  61. import { connect } from 'react-redux';
  62. import { moreWeather } from '../actions'
  63. import loadMoreComponent from '../components/loadMore'
  64.  
  65. const mapStateToProps = state => (console.log('loadMoreComponent', state), {
  66. state: state.weather
  67. });
  68.  
  69. const mapDispatchToProps = dispatch => ({
  70. moreWeather: (loadMore) => dispatch(moreWeather(loadMore))
  71. });
  72.  
  73. export default connect(
  74. mapStateToProps,
  75. mapDispatchToProps)(loadMoreComponent);
  76.  
  77. import React, { Component } from 'react';
  78. import { connect } from 'react-redux';
  79. import WheatherLayoutComponent from '../components/WheatherLayout'
  80.  
  81. const mapStateToProps = state => (console.log('WheatherLayoutComponent ', state), {
  82. cityStore: state.weather
  83. });
  84.  
  85. export default connect(
  86. mapStateToProps,
  87. null)(WheatherLayoutComponent);
  88.  
  89. (state, action) => {
  90. weather: weatherReducer(state, action)
  91. loadMore: loadMoreReducer( state, action)
  92. }
  93.  
  94. const mapStateToProps = state => (console.log('loadMoreComponent', state), {
  95. state: state.loadMore // not state.weather
  96. });
Add Comment
Please, Sign In to add comment