/**
+ Request information about the car
+ @param model - model of car
+ @param id - id of car
**/
function requestInfo(model, id) {
return `${model} with id: ${id}`
}
/**
+ Buy the car
+ @param model - model of car
+ @param id - id of car
**/
function buyVehicle(model, id) {
return `You purchased ${model} with id: ${id}`
}
/**
+ Arrange viewing for car
+ @param model - model of car
+ @param id - id of car
**/
function arrangeViewing(model, id) {
return `You have successfully booked a viewing of ${model} (${id})`
}
/**
+ A generic execute function
+ Takes a receiver and a command
**/
export default function execute(receiver, command) {
return receiver[command.action] && receiver[command.action](...command.params)
}
import execute from 'executor.js'
import TeslaSalesControl from 'receiver.js'
// Arrange a viewing
execute(TeslaSalesControl, {
action: 'arrangeViewing',
param: ['Model S', '123'],
})
// Request Info
execute(TeslaSalesControl, {
action: 'requestInfo',
param: ['Model S Battery', '123342'],
})
// Buy a Car!
execute(TeslaSalesControl, {
action: 'buyVehicle',
param: ['Tesla 3', '23243425'],
})
import { combineReducers } = 'redux';
function arrangeViewing(state, action) {
switch(action.type) {
case "ARRANGE_VIEWING":
const { model, id } = action.data;
return `${model} and ${id}`
default:
return ""
}
}
function requestInfo(state, action) {
switch(action.type) {
case "REQUEST_INFO":
const { model, id } = action.data;
return `${model} and ${id}`
default:
return ""
}
}
function buyVehicle(state, action) {
switch(action.type) {
case "BUY_VEHICLE":
const { model, id } = action.data;
return `${model} and ${id}`
default:
return false
}
}
const rootReducer = combineReducers({
arrangeViewing,
requestInfo,
buyVehicle
});
export default rootReducer;
import { applyMiddleware, createStore } from 'redux'
import createLogger from 'redux-logger'
import ReduxThunk from 'redux-thunk'
import rootReducer from '../imports/client/reducers/rootReducer'
// create a logger
const logger = createLogger()
const middleware = [ReduxThunk, logger]
const Store = createStore(rootReducer, {}, applyMiddleware(...middleware))
export default Store