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

redoop

v1.0.2

Published

Redux OOP class wrappers

Downloads

1

Readme

redoop

npm version Build Status

Redux OOP class wrappers

Do you love how easy it is to write tests for states outside your React components but too tired of all the boilerplate in Redux? This small package might help you with that.

Table of Contents

Getting Started

npm install --save redoop

Basic Usage

import React from 'react';
import {State} from 'redoop';
import {connect} from 'react-redux';

const TodoList = ({todos, setTodos, text, setText, setState}) => (
  <div>
    <ul>
      {todos.map(todo => <li>{todo}</li>)}
    </ul>
    <input 
      type="text" 
      value={text} 
      onChange={e => setText(e.target.value)}
    />
    <button 
      onClick={() => {
        setTodos(todos.concat(text));
        setText("");
        // or simply
        setState({
          todos: todos.concat(text),
          text: ''
        });
      }
    />
  </div>
);

const todoState = new State("todos", {
  // define your initial state here
  todos: [],
  text: "",
});


const mapStateToProps = (state) => todoState.getState(state);
/* or get only the props you're interested in
const mapStateToProps = (state) => ({

  // reselect getters are automatically defined
  todos: todoState.getTodos(state),
  text: todoState.getText(state),
});
*/

const mapDispatchToProps = todoState.getActionCreators();
/* same here, you can just get the action creators you want to use
const mapDispatchToProps = {

  // a default action creator is also defined for each prop in initial state
  setTodos: todoState.setTodos,
  setText: todoState.setText,
  
  // and you can even use setState just like a React.Component
  // to set multiple props at once
  setState: todoState.setState
};
*/

export default connect(mapStateToProps, mapDispatchToProps)(TodoList);

Advance Usage

  • todo

Adding to Redux Store

import {State} from 'redoop';
import {combineReducers} from 'redux';

const todoState = new State("todos");

// combine all your created states here
export const makeRootReducer = (asyncReducers) => {
  return combineReducers({
    ...asyncReducers,
    [todoState.stateKey]: todoState.reduce
  });
};

// or you can use this utility for injecting state inside your routes
export const injectState = (store, state) => {
  store.asyncReducers[state.stateKey] = state.reduce;
  store.replaceReducer(makeRootReducer(store.asyncReducers));
};

API Reference

  • todo