Vending Machine Basic API implementation, user interface lovely made with React, Redux, Redux Saga. Live demo.
- React
- React Redux = simple and productive state management
- Redux Saga = clean, readable and highly scalable solution for async actions
- Babel
- Webpack
$ git clone https://github.com/dekeey/vending-machine.git
$ cd vending-machine
$ npm install
$ npm start
Command | Description |
---|---|
npm start | Start webpack development server @ localhost:3000 |
npm run build | Build production bundles to ./build directory |
Since trying to implement an abstract vending machine, i decided to base on some real world examples.
- If we look on that machine, we can see that it has a number of racks, which have a number of slots.
- The number of slots on each rack can be different, so you can sell "big" and "small" products simultaneously.
- So, we have two coordinates "rack literal" and "slot number" to operate with.
- If i was an owner of vending machine, it would be nice to be notified about all the events happened with all possible data, including the slot coordinates.
- If i would have such a data, i could split test product positioning inside the machine to generate more income
#####getSlotDataByIndex(rackLiteral, slotIndex)
returns an object with a slot data
{
rackLiteral,
slotIndex,
product,
quantity
}
#####getMachineData()
returns an object with all content from all racks
#####loadProduct(rack, slotNumber, product, quantity)
load a product to specified slot
#####giveProduct(rackLiteral, slotIndex)
give one product from specified slot
####example
import { vendingMachine } from './core/api/index';
console.log(vendingMachine.getMachineData());
#####addSuccessListener(listener) subscribe the listener(function) to a success events from cashier, e.g. coin was accepted
same but for errors
insert coin, if the coin is good, the balance will be increased and the "Success Listeners" will be executed
get the cashier data (balance)
pay from balance. Returns a promise, which resolved with message if ok, rejected if not
####example
import { cashier } from '../../../core/api/index';
import { COINS } from '../../../core/config/config'
cashier.insertCoin(COINS.KINDNESS);