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

reduxlet

v0.3.0

Published

A small container component with an isolated Redux store

Downloads

7

Readme

Reduxlet

A small container component with an isolated Redux store.

Intro

Manage state of a component just like redux!

Reduxlet create a redux store, which is context-free, for a single container component. Let's use actions and reducer instead of using this.setStaet!

Also, lots of sugar is inside by default. Binding actions to dispatch, composing enhancers and applying middleware become much easier!

Usage

Install via npm.

npm install reduxlet

MyContainer.jsx

import React from 'redux'
import reduxlet from 'reduxlet'
import logger from 'redux-logger'
import persistState from 'redux-localstorage'

const actionTypes = {
  ADD: 'ADD'
}

const actions = {
  add: () => ({
    type: actionTypes.ADD
  })
}

const reducer = (state = {count: 0}, action) => {
  switch (action.type) {
    case actionTypes.ADD:
      return {
        ...state,
        count: state.count + 1
      }
  }
  return state
}

const middlewares = [
  logger
]

const enhancers = [
  persistState()
]

class MyComponent () {
  render () {
    const { count, actions } = this.props

    return (
      <div>
        <span>{count}</span>
        <button onClick={actions.add}>Add</button>
      </div>
    )
  }
}

export default reduxlet({
  actions,
  reducer,
  middlewares,
  enhancers
})(MyComponent)

actions will be bound to dispatch. But, if you want, you can define your own mapDispatchToProps. Check API!

For further information, please check examples and specs.

API

reduxlet(params: ReduxletParams)(TargetComponent)

All params are optional. Follow your own taste!

Inherent params

  • params.didMount : A function, store => {}, to run after the component mount. This is good place to dispatch some initial actions.
  • params.willUnmount : A function, store => {}, to run before the component unmount. Similar to params.didMount, you can tear down some thing before lose the instance of store.
  • params.devtool : Connect the inner store to redux-devtool. Redux Devtool can communicate only one store. So, if you trying to connect multiple stores, devtool shows only the last connected one

Redux part

  • params.defaultState : defaultState of redux store (if you provide default value to reducer, you don't need it)
  • params.reducer : A reducer for internal redux store. you can use combineReducer. (default: state=> state)
  • params.actions : Action creators which return action object. Reduxlet will bind these creators to the dispatch method.
  • params.middleware : Middlewares. Reduxlet will apply these.
  • params.enhancers : Enhancers. Reduxlet will composes these with applied middlewares.
  • params.store : External redux store. If you provide this, params.defaultState, params.reducer, params.middleware and params.enhancers are ignored. Almost same to connect of react-redux. The only difference is it doesn't access the store by context.

React Redux part

Almost same to connect([mapStateToProps], [mapDispatchToProps], [mergeProps], [options]). I recommend you to check this link!

  • params.mapStateToProps : Same to mapStateToProps argument of connect. (default: state => state)
  • params.dispatchMapProps : Same to dispatchMapProps argument of connect. It doesn't only pass dispatch, also pass actions bound by bindActionCreators (default: dispatch => ({...boundActions, dispatch}))
  • params.mergeProps : Same to mergeProps argument of connect. (default: state => state)
  • params.options : Same to options argument of connect.
    • params.options.pure : If this set false, always render every dispatch and props change. So, it will ignore other options too. (default: true)
    • params.options.areStatesEqual : Use strictEqual by default
    • params.options.areOwnPropsEqual : Use shallowEqual by default
    • params.options.areStatePropsEqual : Use shallowEqual by default
    • params.options.areMergedPropsEqual : Use shallowEqual by default

Contribution

I'm not good at English. If you find some weired expression or typos, feel free to create an issue.

License

ISC, Junyoung Choi 2017.