Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
redux-toolkit
Advanced tools
supply useful tool functions for redux
npm install redux-toolkit
use a hash object to create a redux reducer. Don't need a hug switch block.
import { ADD_TODO, DELETE_TODO, EDIT_TODO, COMPLETE_TODO, COMPLETE_ALL, CLEAR_COMPLETED } from '../constants/ActionTypes';
const initialState = [{
text: 'Use Redux',
completed: false,
id: 0
}];
createReducer({
[ADD_TODO]: (state, { text }) => [{
id: state.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1,
completed: false,
text
}, ...state],
[DELETE_TODO]: (state, { id }) => state.filter(todo =>
todo.id !== action.id
),
[EDIT_TODO]: (state, { id, text }) => state.map(todo =>
todo.id === id ?
Object.assign({}, todo, { text }) :
todo
),
[COMPLETE_ALL]: state => {
const areAllMarked = state.every(todo => todo.completed);
return state.map(todo => Object.assign({}, todo, {
completed: !areAllMarked
}));
},
[CLEAR_COMPLETED]: state => state.filter(todo => todo.completed === false)
}, initialState)
supply a simple way to write action to save your time and make it esaier to read.
without payload
createAction('showAll');
function() {
return {
type: 'showAll'
}
}
string payload
createAction('add', 'value');
function(value) {
return {
type: 'add',
value: value
};
}
object payload
createAction('add', ['num1', 'num2']);
function (num1, num2) {
return {
type: 'add',
payload: {
num1: num1,
num2: num2
}
};
}
create by a function
createAction('add', (num1, num2) => {
number1: num1,
number2: num2,
other: num1 * num2
})
function (num1, num2) {
var getAction = (num1, num2) => {
number1: num1,
number2: num2,
other: num1 * num2
};
return {
type: 'add',
payload: getAction(num1, num2)
};
}
FAQs
supply useful utils for redux
The npm package redux-toolkit receives a total of 2,641 weekly downloads. As such, redux-toolkit popularity was classified as popular.
We found that redux-toolkit 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.