Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //actions/mensajes.js
- export const LOAD_MESSAGES = 'LOAD_MESSAGES';
- export const ADD_MESSAGE = 'ADD_MESSAGE';
- export const SET_ACTUAL_MESSAGE = 'SET_ACTUAL_MESSAGE';
- export const loadMessages = mensajes => ({
- type: LOAD_MESSAGES,
- mensajes
- });
- export const addMessage = mensaje => ({
- type: ADD_MESSAGE,
- mensaje
- });
- export const setActualMessage = texto =>({
- type:SET_ACTUAL_MESSAGE,
- texto
- });
- //*******************************************************************//
- //reducers/mensajes.js
- import * as ActionType from '../actions/mensajes';
- import { combineReducers } from 'redux';
- import { mensajesMockeados } from '../helpers/mokedData';
- //const MENSAJES_INITIAL_STATE = [];
- const MENSAJES_INITIAL_STATE = mensajesMockeados;
- const MENSAJE_ACTUAL_INITIAL_STATE = {
- texto:''
- };
- const mensajes = (state = MENSAJES_INITIAL_STATE, action) => {
- switch (action.type) {
- case ActionType.LOAD_MESSAGES:
- return action.mensajes;
- case ActionType.ADD_MESSAGE:
- return [...state, action.mensaje];
- default:
- return state;
- }
- };
- const mensajeActual = (state= MENSAJE_ACTUAL_INITIAL_STATE, action) =>{
- switch (action.type) {
- case ActionType.SET_ACTUAL_MESSAGE:
- return {...state, texto:action.texto};
- default:
- return state;
- }
- };
- export default combineReducers({
- mensajes,
- mensajeActual
- });
- //*******************************************************************//
- //reducers/index.js
- import { combineReducers } from 'redux';
- import mensajes from './mensajes';
- export default mensajes;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement