Socket
Book a DemoInstallSign in
Socket

redux-rubik-reducer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

redux-rubik-reducer

redux-rubik-reducer

2.1.0
unpublished
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

redux-rubik-reducer (R3)

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

travis Coverage Status npm downloads

Installation

npm install --save redux-rubik-reducer

Example usage

Basic usage

//Import methods and constants
import {
  reducer,
  createAction,
  initialState,
  ActionType
} from "redux-rubik-reducer";

//Initialize state
let state = initialState;

//Create action passing ActionType as parameter
let action = createAction(ActionType.ROTATE_RIGHT);

//Get new state
state = reducer(state, action);

Advanced usage

//Import methods and constants
import {
  reducer,
  createAction,
  actionHandlers,
  initialState,
  ActionType,
  CellType
} from "redux-rubik-reducer";

//Create custom CellType
CellType.Custom = "YOUR_CUSTOM_CELL_TYPE_CONSTANT";

//Create custom state
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]
  ]
];

//Add custom ActionType
ActionType.CUSTOM_ACTION = "YOUR_CUSTOM_ACTION_TYPE_CONSTANT";

//Create custom action
let action = createAction(ActionType.CUSTOM_ACTION);

//Use actionHandlers
let changedCustomState = actionHandlers.rotateRight(customState);

//Create custom action handlers
/**
 * @param {string[][][]} state
 * @returns {string[][][]}
 */
actionHandlers.customHandler = state => {
  /*Your code*/
};

//Use it
actionHandlers.customHandler(changedCustomState);

//Customize reducer function
/**
 * @param {string[][][]} state
 * @param {Action} action
 * @returns {string[][][]}
 */
const customReducer = (state, action) => {
  //Handle your custom action(s) first
  switch (action.type) {
    case ActionType.CUSTOM_ACTION:
      return actionHandlers.customHandler(state);
    //If not custom action handle it with reducer function
    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.

Keywords

redux

FAQs

Package last updated on 27 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.