redux-rubik-reducer (R3)
An npm package to get the redux compatible reducer function and action creator for Rubik's cube state handling.

Installation
npm install --save redux-rubik-reducer
Example usage
Basic usage
import {
reducer,
createAction,
initialState,
ActionType
} from "redux-rubik-reducer";
let state = initialState;
let action = createAction(ActionType.ROTATE_RIGHT);
state = reducer(state, action);
Advanced usage
import {
reducer,
createAction,
actionHandlers,
initialState,
ActionType,
CellType
} from "redux-rubik-reducer";
CellType.Custom = "YOUR_CUSTOM_CELL_TYPE_CONSTANT";
let customState = [
[
[CellType.BLUE, CellType.RED, CellType.GREEN],
[CellType.YELLOW, CellType.RED, CellType.ORANGE],
[CellType.BLUE, CellType.BLUE, CellType.ORANGE]
],
[
[CellType.YELLOW, CellType.WHITE, CellType.WHITE],
[CellType.RED, CellType.YELLOW, CellType.GREEN],
[CellType.WHITE, CellType.BLUE, CellType.ORANGE]
],
[
[CellType.RED, CellType.ORANGE, CellType.BLUE],
[CellType.WHITE, CellType.ORANGE, CellType.YELLOW],
[CellType.WHITE, CellType.WHITE, CellType.GREEN]
],
[
[CellType.GREEN, CellType.ORANGE, CellType.YELLOW],
[CellType.BLUE, CellType.WHITE, CellType.GREEN],
[CellType.WHITE, CellType.YELLOW, CellType.YELLOW]
],
[
[CellType.RED, CellType.BLUE, CellType.RED],
[CellType.RED, CellType.GREEN, CellType.WHITE],
[CellType.ORANGE, CellType.GREEN, CellType.GREEN]
],
[
[CellType.BLUE, CellType.GREEN, CellType.ORANGE],
[CellType.YELLOW, CellType.BLUE, CellType.RED],
[CellType.YELLOW, CellType.ORANGE, CellType.RED]
]
];
ActionType.CUSTOM_ACTION = "YOUR_CUSTOM_ACTION_TYPE_CONSTANT";
let action = createAction(ActionType.CUSTOM_ACTION);
let changedCustomState = actionHandlers.rotateRight(customState);
actionHandlers.customHandler = state => {
};
actionHandlers.customHandler(changedCustomState);
const customReducer = (state, action) => {
switch (action.type) {
case ActionType.CUSTOM_ACTION:
return actionHandlers.customHandler(state);
default:
return reducer(state, action);
}
};
Contributing
Any contribution you make is greatly appreciated. :)
License
This project is licensed under the terms of the
MIT license.