
Product
Introducing Socket Scanning for OpenVSX Extensions
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.
Tools for redacting the noise of Redux.
Redux is an amazing tool for thinking of complex data in terms of small transformations!
However, projects that use redux can fail to smooth out norms, and often end devolve into gigantic, ugly case statements that are hard to maintain. The creators of Redux have recognized this and built some tools for smoothing out these rough edges, but they are not particularly readable. They provide the kind of API that requires memorization and consistent use.
This is a series of small tested tools that let you:
Instead of generating a bunch of constants and then associating those with actions, the library assumes actions don't need to be unique snowflakes, and you don't need to know the name of the constants. You will generate actions and then use them!
import { createActions } from 'redaxted'
const actions = createActions([
'incrementCounter',
'decrementCounter',
// ... etc
])
Given access to the dispatch function
import actions from './path/to/actions/generated/above'
const onClick = (_event) => {
disptach(actions.incrementCounter())
}
Data passed in to the action gets normalized. There is always a type and a
payload attribute on the returned action data. The payload is a normalized
version of the value passed in. The goal of normalizing is to assure that the
payload is always an object or an array that can be easily destructured without
type checking. Here are some examples:
action.incrementCounter()
/*
{
type: 'incrementCounter',
payload: {}
}
*/
action.incrementCounter(undefined)
/*
{
type: 'incrementCounter',
payload: {}
}
*/
action.incrementCounter(null)
/*
{
type: 'incrementCounter',
payload: {}
}
*/
action.incrementCounter({increaseBy: 10})
/*
{
type: 'incrementCounter',
payload: {increaseBy: 10}
}
*/
action.incrementCounter([10])
/*
{
type: 'incrementCounter',
payload: [10]
}
*/
Literals are packed into an object via a value key. Here are some examples of
that:
action.incrementCounter(false)
/*
{
type: 'incrementCounter',
payload: { value: false }
}
*/
action.incrementCounter(10)
/*
{
type: 'incrementCounter',
payload: { value: 10 }
}
*/
action.incrementCounter('huh?')
/*
{
type: 'incrementCounter',
payload: { value: 'huh?' }
}
*/
These normalizations reduce the need for type systems or defensive programming.
Instead of creating massive case statements, reducers are created with simple transformers that respond to a single action type within a single area of the store. For a given area of the store, different type related reducers are combined together.
To create a basic action for a type use the createReducer and chain call
transform with a transformer function.
Transformer functions take the form (state, payload) => newState.
Here is an example:
import actions from './path/to/actions'
const addReducer = createReducer(actions.addToThings)
.transform((state, payload) => [...state, payload])
addReducer([], actions.addToThings('my first thing'))
// [ 'my first thing' ]
Setting initial state is also done with a chaining call:
import actions from './path/to/actions'
const addReducer = createReducer(actions.addToThings)
.transform((state, payload) => [...state, payload.value])
.initialState([])
addReducer()
// []
Creating reducers that have a single responsibility, means that you need to combine them via functional composition. A reducer equivalent to the gigantic case statement is generated by passing the return values of each small reducer to the next in line.
import actions from './path/to/actions'
const addReducer = createReducer(actions.addToThings)
.transform((state, payload) => [...state, payload.value])
const removeReducer = createReducer(actions.removeFromThings)
.transform((state, payload) => {
return state.filter((element) => element !== payload.value)
})
const reducer = composeReducers([
addReducer,
removeReducer
])
let newState = reducer([], action.addToThings('thing 1'))
// ['thing 1']
newState = reducer([], action.addToThings('thing 2'))
// ['thing 1', 'thing 2']
newState = reducer(newState, action.removeFromThings('thing 1'))
// ['thing 2']
The composeReducers function also chains to allow an initial state, and of
course this initial state overrides individual state for the reducers that are
being combined:
const reducer = composeReducers([
addReducer,
removeReducer
]).initialState([])
This is open source. Use issues, PRs and other methods to request or suggest
changes. There is a code of conduct. Tests can be run with yarn test.
The source uses es6 and so index.js the entry point is a Babel compiled
version of that code. You can rebuild on your branch with yarn build.
FAQs
Tools for redacting the noise of Redux
We found that redaxted 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.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies