
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
create-duck
Advanced tools
CLI script for creating Redux ducks. Uses redux-logic middleware and reselect (optionally).
Generates duck file, which can be modified/extended with extra types/actions/logic.
Created for personal needs to avoid writing boilerplate code over and over.
Install NPM package globally:
npm i -g create-duck
Run create-duck
command. You will be prompted to enter:
:warning: Remember to import reducer/logic from duck and add them to root reducer/logic.
Running create-duck
command and entering user-data
as duck name will generate in current working directory user-data.js
file with following content:
import { createLogic } from 'redux-logic';
export const name = 'default';
const prefix = `${name}/`;
/*
* TYPES
*/
const FETCH_DEFAULT = `${prefix}FETCH_DEFAULT`;
const FETCH_DEFAULT_SUCCESS = `${prefix}FETCH_DEFAULT_SUCCESS`;
const FETCH_DEFAULT_CANCEL = `${prefix}FETCH_DEFAULT_CANCEL`;
export const types = {
FETCH_DEFAULT,
FETCH_DEFAULT_SUCCESS,
FETCH_DEFAULT_CANCEL,
};
/*
* ACTIONS
*/
const fetchDefault = options => ({
type: FETCH_DEFAULT,
payload: {
url: 'default',
method: 'post',
...options,
},
});
const fetchDefaultSuccess = data => ({
type: FETCH_DEFAULT_SUCCESS,
data,
});
const fetchDefaultCancel = () => ({
type: FETCH_DEFAULT_CANCEL,
});
export const actions = {
fetchDefault,
fetchDefaultSuccess,
fetchDefaultCancel,
};
/*
* SELECTORS
*/
const getState = state => state[name];
const getDefault = state => getState(state);
export const selectors = {
getState,
getDefault,
};
/*
* LOGIC
*/
const fetchDefaultLogic = createLogic({
type: FETCH_DEFAULT,
cancelType: [FETCH_DEFAULT_CANCEL],
latest: true,
process({ action: { payload }, httpClient, cancelled$ }) {
return httpClient.cancellable(payload, cancelled$)
.then(({ data }) => fetchDefaultSuccess(data));
},
});
export const logic = {
fetchDefaultLogic,
};
/*
* REDUCER
*/
const initialState = {};
const reducer = (state = initialState, action) => {
switch (action.type) {
case FETCH_DEFAULT_SUCCESS:
return {
...action.data
};
default:
return state;
}
};
export default reducer;
FAQs
CLI script for creating Redux ducks
The npm package create-duck receives a total of 1 weekly downloads. As such, create-duck popularity was classified as not popular.
We found that create-duck 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
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.