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.
@acpaas-ui/js-redux-utils
Advanced tools
The Redux Utils package provides some helpers and bootstrap utils to ease the redux setup.
The Redux Utils package provides some helpers and bootstrap utils to ease the redux setup.
NPM
npm i -S @acpaas-ui/js-redux-utils
Yarn
yarn add @acpaas-ui/js-redux-utils
// ES2015
import { progressReducer } from '@acpaas-ui/js-redux-utils';
There are 3 HORs available: progress
, basicType
and target
. The usage of combineReducers
is required for these HORs to work.
The progress HOR wraps the state in an object detailing the status of your data:
{
loading: true/false,
created: 'Thu Feb 15 2018 13:36:31 GMT+0100 (CET)',
lastUpdated: 'Thu Feb 15 2018 13:36:31 GMT+0100 (CET)',
error: 'Custom error',
result: {
id: 'my-item'
}
}
You can update the status by providing the loading
flag or an err
message in your action:
{
type: 'DO_STUFF',
loading: true/false,
err: 'Something went wrong'
}
By wrapping your reducer, you maintain control over what is stored in the result
, without having to bother with the loading state. You just have to provide a type and a reducer function:
const myReducer = (state, action) => {
if (action.type === 'STUFF_LOAD') {
return {
...state,
stuff: action.stuff
};
}
return state;
};
const progressReducer = progress('STUFF', myReducer);
The progressReducer will only trigger for actions starting with the type you provided. We use namespacing by trailing slash /
:
type = 'ARTICLES';
'ARTICLES/LOAD' will match
'ARTICLES/LOAD' will match
'ARTICLES/PAGE' will match
'NEWS_ARTICLES' will not match
'ARTICLES_LOAD' will not match
'ARTICLE/LOAD' will not match
In a lot of applications there are similar data types that require a minimum of functionality:
To avoid a lot of copy pasta the redux-utils
package provides a very basic HOR to handle this use case.
Simply provide a type (defaults to BASIC_DEFAULT
) and an (optional) initial value:
const newsReducer = basicType({
type: 'NEWS'
}, null);
Now you can update the news type by dispatching actions using the type you provided as a namespace:
dispatch({
type: 'NEWS/LOAD', // <TYPE>/LOAD
data: { // will always look for a 'data' property
id: '1',
title: 'How cool is this?'
}
});
By default the basicType
HOR will assume you are handling a single item. If you need to handle arrays, set the dataType
option to list
:
const newsReducer = basicType({
type: 'NEWS',
dataType: 'list',
}, []);
Now you can use the same LOAD
action to set the state:
dispatch({
type: 'NEWS/LOAD',
data: [{
id: '1',
title: 'How cool is this?'
}]
});
or use the LOAD_MORE
action to append new items to the state:
dispatch({
type: 'NEWS/LOAD_MORE',
data: [{
id: '2',
title: 'Need more content.'
}]
});
Note:
When you call the LOAD_MORE
action on a single
data type, the reducer will fallback to the LOAD
action, overwriting the state.
You can use the progress
HOR by setting progress
to true
in the settings:
const newsReducer = basicType({
type: 'NEWS',
dataType: 'list',
progress: true,
}, []);
You can still dispatch loading
and error
states the same way:
dispatch({
type: 'NEWS/LOAD',
loading: true,
});
The target reducer stores the result of the provided reducer for the provided target in the store. This way, you can reuse reducer logic and without having to manage an extra layer of complexity.
{
filters: {
search: {...},
home: {...},
users: {...}
}
}
The targetReducer
expects a type
, reducer
and optional initialState
to work:
const filterReducer = targetReducer({ type: 'FILTERS' }, myFilterReducer, {});
The type
will be the namespace verified with the action type.
You can update targets by setting the target
property on the dispatched action:
dispatch({
type: 'FILTERS/LOAD',
target: 'search',
filters: [...],
});
The state will be updated accordingly:
{
filters: {
search: [...]
}
}
You can wrap your targets in a progressReducer
by setting progress
to true
in the settings:
const filterReducer = targetReducer({
type: 'FILTERS',
progress: true
}, myFilterReducer, {});
Now you can dispatch loading
and error
states the same as before:
dispatch({
type: 'FILTERS/LOAD',
loading: true,
target: "search"
});
The state will be updated accordingly:
{
filters: {
search: {
loading: true,
error: null,
result: null,
...
}
}
}
FAQs
[![js-redux-utils-status]][js-redux-utils-package]
The npm package @acpaas-ui/js-redux-utils receives a total of 9 weekly downloads. As such, @acpaas-ui/js-redux-utils popularity was classified as not popular.
We found that @acpaas-ui/js-redux-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers 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.