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

redux-thunk-it

v1.2.5

Published

Beautify the format of stores, actions, reducers in react-redux with redux-thunk

Downloads

46

Readme

redux-thunk-it

Beautify the format of stores, actions, reducers in react-redux with redux-thunk

Installation

Install with npm:

npm install redux-thunk-it

API

import thunk, { combineReducers, thunkActions } from 'react-thunk-it'
  1. combineReducers: see Example below
  2. thunkActions: see Example below
  3. thunk: Redux Thunk
  4. thunk.withExtraArgument: Injecting a Custom Argument MUST using {} as parameter
  5. dispatch
    • type:
      1. ${store_name}/${reducer_name} to dispatch to a specific reducer in a specific store
      2. /${reducer_name} to dispatch to a specific reducer in every store
    • payload: anything
// dispatch to a specific reducer
dispatch({
  type: 'test/save',
  payload: {
    ...
  }
})

// dispatch to a action in this store
dispatch(this.xxx())

// dispatch to a action in other store
import { Test2 } from './'
dispatch(Test2.xxx())

Example

  1. ./index.js
import React from 'react'
import ReactDOM from 'react-dom'
import { createStore, applyMiddleware, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import thunk from 'redux-thunk-it'

import App from './App'
import stores from './stores'

const store = createStore(
  combineReducers(stores),
  applyMiddleware(thunk),
)

ReactDOM.render((
  <Provider store={store}>
    <App />
  </Provider>
), document.getElementById('root'))
  1. ./stores/index.js
import { combineReducers, thunkActions } from 'redux-thunk-it'

import test1 from './test1'
import test2 from './test2'

export default combineReducers({
  test1,
  test2
})

export const Test1 = thunkActions(test1)
export const Test2 = thunkActions(test2)
  1. ./stores/test1.js & ./stores/test2.js
export default {
  state: {
    data: {},
    loading: false,
    err: ''
  },

  actions: {
    get_something: function (message = '') {
      const { dispatch } = this.props
      
      // const { custom arguments injected by withExtraArgument...  } = this

      dispatch({
        type: 'test/save',
        payload: {
          loading: true
        }
      })

      fetch('http://localhost/something')
      .then(res => res.json())
      .then(data => {
        dispatch({
          type: 'test/save',
          payload: {
            data,
            loading: false
          }
        })
      })
      .catch(err => {
        dispatch({
          type: 'test/save',
          payload: {
            loading: false
            err,
          }
        })
      })

      
    }
  },

  reducers: {
    save: (state, payload) => {
      return {
        ...state,
        ...payload
      }
    }
  }
}
  1. ./App.js
import { connect } from 'react-redux'
import { Test1, Test2 } from './stores'

class App extends Component {
  componentDidMount() {
    const { dispatch } = this.props

    dispatch(Test1.get_something('xxx'))
  }
  render() {
    const { test1, test2 } = this.props

    console.log(test1, test2)

    return (
      <div />
    );
  }
}

export default connect(state => state)(App)