Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create-duck

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-duck - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

2

package.json
{
"name": "create-duck",
"version": "0.2.2",
"version": "0.2.3",
"description": "CLI script for creating Redux ducks",

@@ -5,0 +5,0 @@ "main": "./src/create-duck.js",

# create-duck
CLI script for creating Redux ducks
CLI script for creating [Redux ducks](https://github.com/erikras/ducks-modular-redux).
Uses [redux-logic](https://github.com/jeffbski/redux-logic) middleware.
Generates boilerplate duck file, which can be modified/extended with extra types/actions/logic.
## Motivation
Created for personal needs to avoid writing boilerplate code over and over.
## Usage
Install NPM package globally:
```
npm i -g create-duck
```
Run `create-duck` command in duck destionation directory. You will be prompted to enter duck name.
:warning: Remember to import reducer/logic from duck and add them to root reducer/logic.
## Example
Running `create-duck` command and entering `user-data` as duck name will generate in working directory `user-data.js` file with following content:
```
import { createLogic } from 'redux-logic';
/*
* TYPES
*/
const prefix = 'userData/';
const FETCH_USER_DATA = `${prefix}FETCH_USER_DATA`;
const FETCH_USER_DATA_SUCCESS = `${prefix}FETCH_USER_DATA_SUCCESS`;
const FETCH_USER_DATA_CANCEL = `${prefix}FETCH_USER_DATA_CANCEL`;
/*
* ACTIONS
*/
const fetchUserDataSuccess = data => ({
type: FETCH_USER_DATA_SUCCESS,
data,
});
const fetchUserData = options => ({
type: FETCH_USER_DATA,
payload: {
url: 'userData',
method: 'post',
...options,
},
});
const fetchUserDataCancel = () => ({
type: FETCH_USER_DATA_CANCEL,
});
/*
* REDUCER
*/
const initialState = {};
const reducer = (state = initialState, action) => {
const actions = {
[FETCH_USER_DATA_SUCCESS]: () => ({
...action.data,
}),
};
return (actions[action.type] && actions[action.type]()) || state;
};
/*
* LOGIC
*/
const fetchUserDataLogic = createLogic({
type: FETCH_USER_DATA,
cancelType: [FETCH_USER_DATA_CANCEL],
latest: true,
process({ action: { payload }, httpClient, cancelled$ }) {
return httpClient.cancellable(payload, cancelled$)
.then(({ data }) => fetchUserDataSuccess(data));
},
});
/*
* SELECTORS
*/
const getUserData = state => state;
/*
* EXPORTS
*/
export default reducer;
export const actions = {
fetchUserData,
fetchUserDataSuccess,
fetchUserDataCancel,
};
export const types = {
FETCH_USER_DATA,
FETCH_USER_DATA_SUCCESS,
FETCH_USER_DATA_CANCEL,
};
export const logic = {
fetchUserDataLogic,
};
export const selectors = {
getUserData,
};
```

@@ -83,3 +83,3 @@ module.exports = (names) => {

export const actions = {
fetch${Name},
fetch${Name},
fetch${Name}Success,

@@ -100,5 +100,5 @@ fetch${Name}Cancel,

export const selectors = {
get${Name},
get${Name},
};`
);
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc