Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
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 other = num1 * num2;
return {
type: 'add',
payload: {
number1: num1,
number2: num2,
other
}
};
}
FAQs
supply useful utils for redux
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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.