Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //actions/mensajes.js
  2. export const LOAD_MESSAGES = 'LOAD_MESSAGES';
  3. export const ADD_MESSAGE = 'ADD_MESSAGE';
  4. export const SET_ACTUAL_MESSAGE = 'SET_ACTUAL_MESSAGE';
  5.  
  6. export const loadMessages = mensajes => ({
  7.    type: LOAD_MESSAGES,
  8.    mensajes
  9. });
  10.  
  11. export const addMessage = mensaje => ({
  12.    type: ADD_MESSAGE,
  13.    mensaje
  14. });
  15.  
  16. export const setActualMessage = texto =>({
  17.    type:SET_ACTUAL_MESSAGE,
  18.    texto
  19. });
  20.  
  21. //*******************************************************************//
  22. //reducers/mensajes.js
  23. import * as ActionType from '../actions/mensajes';
  24. import { combineReducers } from 'redux';
  25. import { mensajesMockeados } from '../helpers/mokedData';
  26.  
  27. //const MENSAJES_INITIAL_STATE = [];
  28. const MENSAJES_INITIAL_STATE = mensajesMockeados;
  29. const MENSAJE_ACTUAL_INITIAL_STATE = {
  30.    texto:''
  31. };
  32.  
  33. const mensajes = (state = MENSAJES_INITIAL_STATE, action) => {
  34.    switch (action.type) {
  35.        case ActionType.LOAD_MESSAGES:
  36.            return action.mensajes;
  37.        case ActionType.ADD_MESSAGE:
  38.            return [...state, action.mensaje];
  39.        default:
  40.            return state;
  41.    }
  42. };
  43.  
  44. const mensajeActual = (state= MENSAJE_ACTUAL_INITIAL_STATE, action) =>{
  45.    switch (action.type) {
  46.        case ActionType.SET_ACTUAL_MESSAGE:
  47.            return {...state, texto:action.texto};
  48.        default:
  49.            return state;
  50.    }
  51. };
  52.  
  53. export default combineReducers({
  54.    mensajes,
  55.    mensajeActual
  56. });
  57.  
  58. //*******************************************************************//
  59. //reducers/index.js
  60. import { combineReducers } from 'redux';
  61. import mensajes from './mensajes';
  62.  
  63. export default mensajes;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement