Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
redux-functions
Advanced tools
Readme
A set of functions allow you to create action-creators, reducers, action-type faster and type-safer.
NPM
npm i redux-functions
Yarn
yarn add redux-functions
CDN
<!-- format https://cdn.jsdelivr.net/npm/redux-functions@{{VERSION}}/umd/main.js -->
<script src="https://cdn.jsdelivr.net/npm/redux-functions@0.0.9/umd/main.js"></script>
toType
In a large scale of redux application, there are tons of action types. It is always a nightmare for developers to think of an unique action name.
toType
allows you to add a prefix for the action name, so it is easier to debug and manage.
For example
import { toType } from "redux-functions";
// create an action type generator
const type = toType("TABLE_TENNIS");
// export the actions type for later use
export const PING = type("PING"); // "TABLE_TENNIS::PING"
export const PONG = type("PONG"); // "TABLE_TENNIS::PONG"
toActionCreator
To create an action creator is very simple,
import { toActionCreator } from "redux-functions";
export const ping = toActionCreator("PING");
// In Typescript, you can also create a type-safe action creator
export const pong = toActionCreator<boolean>("PONG");
// to use it
ping() // { type: "PING" }
pong(true) // { type: "DELAY_PONG", payload: true };
Inspired by redux-toolkit, You can also use the action creator to verify an unknown action.
// In Javascript, using "=="
ping == { type: "PING" } // true
ping == { type: "PONG" } // false
// In Typescript
ping.test({ type: "PING" }) // true
ping.test({ type: "PONG" }) // false
There is a caveat about the redux actions generated by redux-functions
.
All the actions generated by toActionCreator
will be in the format of
import type { Action } from "redux";
interface AppAction<T> extends Action<string>{
payload: T;
}
toReducer
To create a reducer without boilerplate. toReducer
takes two parameters, action type and default value, i.e. toReducer(action, defaultValue)
.
For example
import { toReducer } from "redux-functions";
import { combineReducers } from "redux";
const ping = toReducer("PING", false);
const pong = toReducer("PONG", false);
const reducers = combineReducers({ ping, pong });
Unlike redux-toolkit's createReducer
, toReducer
only handle one single action for each generated reducer.
If you would like to have more customisation on the reducer handling, please check redux-toolkit.
FAQs
Unknown package
The npm package redux-functions receives a total of 64 weekly downloads. As such, redux-functions popularity was classified as not popular.
We found that redux-functions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.