npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

magic-redux-generator

v0.1.6

Published

Component for generate redux actions/reducer

Downloads

1

Readme

magic-redux-generator

Simple component for generate redux actions/reducer

Component in development. I accept suggestions.

Installation

For install: npm install magic-redux-generator --save

Instance methods

fetchItem

| Prop name | Type | Description | Example | |--------------|----------|----------------------------------------|------------| | urlExtension | String | Url sufix | "/id" | | queryParams | Object | Query url params | {limit:15} | | responseType | String | WS response sufix | "users" | | preDispatch | Function | Function to execute before do dispatch | () => {} | | postDispatch | Function | Function to execute after do dispatch | () => {} |

fetch

| Prop name | Type | Description | Example | |---------------|----------|----------------------------------------|------------| | urlExtension | String | Url sufix | "/5" | | queryParams | Object | Query url params | {limit:15} | | responseType | String | WS response sufix | "users" | | responseTotal | String | WS response total sufix | "total" | | preDispatch | Function | Function to execute before do dispatch | () => {} | | postDispatch | Function | Function to execute after do dispatch | () => {} |

create

| Prop name | Type | Description | Example | |--------------|----------|---------------------------------------|-----------------------------------| | data | Object | Object with create data | {username:example, password:1234} | | urlExtension | String | Url sufix | "/users" | | queryParams | Object | Query url params | {limit:15} | | postDispatch | Function | Function to execute after do dispatch | () => {} |

update

| Prop name | Type | Description | Example | |--------------|----------|---------------------------------------|-----------------------------------------| | data | Object | Object with update data | {id:3, username:example, password:1234} | | urlExtension | String | Url sufix | "/3" | | queryParams | Object | Query url params | {limit:15} | | postDispatch | Function | Function to execute after do dispatch | () => {} |

delete

| Prop name | Type | Description | Example | |--------------|----------|---------------------------------------|------------| | urlExtension | String | Url sufix | "/3" | | queryParams | Object | Query url params | {limit:15} | | postDispatch | Function | Function to execute after do dispatch | () => {} |

deleteRows

| Prop name | Type | Description | Example | |------------------|----------|--------------------------------------------|------------| | urlExtension | String | Url sufix | "/3" | | queryParams | Object | Query url params | {limit:15} | | postDispatchItem | Function | Function to execute after delete each item | () => {} | | postDispatchAll | Function | Function to execute after delete all items | () => {} |

More instance methods

| Instance method | Description | Example | |-----------------|--------------------------------|-------------------------------------| | setList | Set the reducer list value | dispatch(actions. setList([])) | | setItem | Set the reducer item value | dispatch(actions.setItem({})) | | setTotal | Set the reducer total value | dispatch(actions.setTotal(32)) | | setFetching | Set the reducer fetching value | dispatch(actions.setFetching(true)) |

Project Example

You can check this component with this project example for react-native.

git clone https://github.com/luisfuertes/testMagicReduxGenerator
cd projectDir && npm install
react-native run-ios

Basic usage

Import: import reduxGenerator from 'magic-redux-generator'

Important: Set Authorization token (only on init): reduxGenerator.webservices.configureToken(yourToken)

Actions.js basic example:

import reduxGenerator from 'magic-redux-generator'

let baseUri = mainUrl + '/users'
let actions = reduxGenerator.createActions(baseUri, 'users')
let types = reduxGenerator.createTypes('users')

//Add custom actions
export default {
  ...actions,

  types,

  yourCustomAction: () => {
    return (dispatch, getState) => {
      ...
      let item = extraData
      dispatch(actions.setItem(item))
    }
  },
}

Reducer.js example:

import reduxGenerator from 'magic-redux-generator'

let userReducer = createReducer('users')
export default userReducer.reducer

Usage example:

Dispatch action:

import actions from './Actions.js'

dispatch(actions.fetch({offset: 0, limit: 10}, 'users'))

And in mapStateToProps:

list: state.users.list,

Error reducer example:

import reduxGenerator from 'magic-redux-generator'
const users = reduxGenerator.createTypes('users')//One per action/reducer generate with reduxGenerator

const initialState = {
  type: null,
  error: null,
};

export default function errorReducer(state = initialState, action = {}) {
  switch (action.type) {

    case users.ACTIONS_ERROR:
      return {
        ...state,
        type: users.ACTIONS_ERROR,
        error: action.error,
      };

    case 'REMOVE_ERROR':
      return {
        ...state,
        error: null,
        type: null,
      };

    default:
      return state;
  }
}