Security News
npm Updates Search Experience with New Objective Sorting Options
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Automate the Redux boilerplate.
This library is still in the idea phase. Please check it out and file any issues you encounter.
npm install --save autodux
And then in your file:
import autodux from 'autodux';
Or using CommonJS syntax:
const autodux = require('autodux');
Redux is great, but you have to make a lot of boilerplate:
It's great that Redux is such a low-level tool. It's allowed a lot of flexibility and enabled the community to experiment with best practices and patterns.
It's terrible that Redux is such a low-level tool. It turns out that:
counter/increment
.Lots of Redux beginners separate all these things into separate files, meaning you have to open and import a whole bunch of files just to get some simple state management in your app.
What if you could write some simple, declarative code that would automatically create your:
Turns out, when you add this simple logic on top of Redux, you can do a lot more with a lot less code.
import autodux from 'autodux';
// This can be used for action creators that pass
// a single argument through as the payload,
// and also for selectors that just select the
// whole reducer state.
const id = x => x;
const counter = autodux({
// the slice of state your reducer controls
slice: 'counter',
// The initial value of your reducer state
initial: 0,
// No need to implement switching logic -- it's
// done for you.
actions: {
increment: {
reducer: state => state + 1
},
decrement: {
reducer: state => state - 1
},
multiply: {
create: id,
reducer: (state, payload) => state * payload
}
},
// No need to select the state slice -- it's done for you.
selectors: {
getValue: id
}
});
What you get from that is an object that looks like this:
{
initial: 0,
actions: {
increment: { [Function]
type: 'counter/increment'
},
decrement: { [Function]
type: 'counter/decrement'
},
multiply: { [Function]
type: 'counter/multiply'
}
},
selectors: {
getValue: [Function: wrapper]
},
reducer: [Function: reducer]
}
Let's explore that object a bit:
const {
selectors: { getValue },
actions: {
increment,
decrement
},
reducer,
initial
} = counter;
const actions = [
increment(),
increment(),
increment(),
decrement()
];
const state = actions.reduce(reducer, initial);
console.log(getValue({ counter: state })); // 2
console.log(increment.type); // 'counter/increment'
FAQs
Automate the Redux boilerplate.
The npm package autodux receives a total of 2,200 weekly downloads. As such, autodux popularity was classified as popular.
We found that autodux 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
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.