New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

reduxt

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

reduxt

Tools for redux

latest
Source
npmnpm
Version
0.0.5
Version published
Maintainers
1
Created
Source

Reduxt - Redux toolbox

Tools to ease generate actions and reducers for redux

npm bundle size npm bundle size npm NPM GitHub last commit

Summary

  • Installation

  • Build

  • Use

Installation

// NPM
npm install reduxt

// Yarn
yarn add reduxt

Build

// NPM
npm run build

// Yarn
yarn build

Use

Generate actions

Without prefix

generateActions(prefix, ...actions);
import { generateActions } from "reduxt";

// actionsAT = Action types
// actionsAC = Actions to dispatch

const [actionsAT, actionsAC] = generateActions(null, "action 1", "action_2", [
  "action 3",
  value => !value
]);

actionsAT.action1 --> ACTION_1
actionsAT.action2 --> ACTION_2
actionsAT.action3 --> ACTION_3

actionsAC.action1() --> {
    type    : 'ACTION_1',
    payload : undefined,
}

actionsAC.action2('Hello!') --> {
    type    : 'ACTION_2',
    payload : 'Hello!',
}

actionsAC.action3(false) --> {
    type    : 'ACTION_3',
    payload : true,
}

With prefix

import { generateActions } from "reduxt";

const [actionsAT, actionsAC] = generateActions(
  "custom prefix",
  "action 1",
  "action_2",
  ["action 3", value => !value]
);

actionsAT.action1 --> 'CUSTOM_PREFIX/ACTION_1'
actionsAT.action2 --> 'CUSTOM_PREFIX/ACTION_2'
actionsAT.action3 --> 'CUSTOM_PREFIX/ACTION_3'

actionsAC.action1() --> {
    type    : 'CUSTOM_PREFIX/ACTION_1',
    payload : undefined,
}

actionsAC.action2('Hello!') --> {
  type    : 'CUSTOM_PREFIX/ACTION_2',
  payload : 'Hello!',
}

actionsAC.action3(false) --> {
    type    : 'CUSTOM_PREFIX/ACTION_3',
    payload : true,
}

Generate reducer

generateReducer(initialState, ...reducers);
import { generateReducer } from "reduxt";

const initialState = {
  test: true,
  foo: "foo"
};

// Reducers

const changeTestValueReducer = (state, { payload }) => ({
  ...state,
  test: payload
});

const toggleTestValueReducer = (state, { payload }) => ({
  ...state,
  test: !state.test
});

const changeFooValue = (state, { payload }) => ({ ...state, foo: payload });

const reducer = generateReducer(initialState, {
  CHANGE_TEST_VALUE: changeTestValueReducer,
  TOGGLE_TEST_VALUE: changeTestValueReducer,
  CHANGE_FOO_VALUE: changeFooValue
});

// Examples

dispatch(actionsAC.changeTestValue(false));
state --> {
    test : false,
    foo  : 'foo',
};

dispatch(actionsAC.toggleTestValue());
state --> {
    test : true,
    foo  : 'foo',
}

dispatch(actionsAC.changeFooValue('Modified'));
state --> {
    test : true,
    foo  : 'Modified',
}

Keywords

redux

FAQs

Package last updated on 18 Aug 2020

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