Giter Club home page Giter Club logo

simplify-redux's Introduction

simplify-redux

A js library containing utilities to simplify tasks involved for setting up redux global state. This library currently provides easy interface for creating constants, action creators return nothing but the action (without any data), and creating reducers.

Installation

npm install simplify-redux

or

git clone [email protected]:anshulsahni/simplify-redux.git
npm install /path/to/clone/repository

Usage

import simplifyRedux from 'simplify-redux'
export default simplifyRedux.getConsts(
'CONSTANT_ONE',
'CONSTANT_TWO',
);

API Reference

getConsts

This function returns an object containing the string constants as properties of object

Example

import { getConsts } from 'simplify-redux';

return getConsts(
'CONSTANT_ONE',
'CONSTANT_TWO',
'CONSTANT_THREE',
);

//returned object
{ CONSTANT_ONE: 'CONSTANT_ONE', CONSTANT_TWO: 'CONSTANT_TWO', CONSTANT_THREE: 'CONSTANT_THREE' }

createSimplefyActionCreators

This method returns an object which contains methods that returns action creators which returns only action without any data

Example

import { getSimpleActionCreators } from 'simplify-redux';

const actions =  {
  ...getSimpleActionCreators(
    'FIRST_ACTION',
    'SECOND_ACTION',
    'THIRD_ACTIONS'
  ),
};

actions.firstAction();

//returned value is action
{ type: 'FIRST_ACTION' };

createReducer

This method takes in initialState and action handlers as arguments, in which handlers is an object with property being the action and value being the functions which will handle those actions

Example

import { createReducer } from 'simplify-redux';

const initialState = {
  messages: [],
};

const onAddMessage = (state, action) => {
  //...code to handle ADD_MESSAGE action
};

const onDeleteMessage = (state, action) => {
  //...code to handle DELETE_MESSAGE action
};

const onUpdateMessage = (state, action) => {
 //...code to handle UPDATE_MESSAGE action
};

export default createReducer(initialState, {
  ADD_MESSAGE: onAddMessage,
  DELETE_MESSAGE: onDeleteMessage,
  UPDATE_MESSAGE: onUpdateMessage,
});

simplify-redux's People

Contributors

anshulsahni avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.