// @flow import { List } from "immutable"; import { combineReducers } from "redux"; import { Model, MessageType } from "./types"; import { SEND_MESSAGE } from './actions'; const init = new Model(); type ActionType = SEND_MESSAGE; function mainReducer( model: Model = init, action: { type: ActionType, payload: Object } ) { switch (action.type) { case SEND_MESSAGE: return sendMessage(model, action.payload); default: return model; } } function nullReducer( model: Model = init, action ) { switch (action.type) { default: return model; } } // private function!! function sendMessage(model, payload) { if (payload) { const message = new MessageType({ text: payload.message }) const new_model = model.updateIn( ["messages"], messages => messages.push(message) ); return new_model; } else { return model; } } const app = combineReducers({ mainReducer, nullReducer }); export default app;