New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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

CLI script for creating Redux ducks

  • 0.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

create-duck

CLI script for creating Redux ducks. Uses 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,
};

FAQs

Package last updated on 12 Oct 2017

Did you know?

Socket

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.

Install

Related posts

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