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-needs

v1.0.4

Published

Wrapping everyday data to your containers in need

Downloads

12

Readme

redux-needs · Build Status codecov david-dm

🎁 Wrapping everyday data to your containers in need 🎁

Bind actions to changes in your Redux state based on the needs of your active Redux components.

Usage | API | Installation | License

Usage

Simple binding

Dispatch the ping action when MyComponent is mounted.

import React from 'react';
import needs from 'redux-needs';

const ping = () => ({
  type: 'PING',
});

const MyComponent = () => (
  <h1>Hello, world!</h1>
);

export default needs([ ping ])(MyComponent);

Complex binding

Dispatch the ping action when MyComponent is mounted and again every time the value of the name property changes.

import React from 'react';
import needs from 'redux-needs';

const ping = () => ({
  type: 'PING',
});

const MyComponent = ({ name }) => (
  <h1>Hello, { name }!</h1>
);

MyComponent.defaultProps = {
  name: 'world',
};

export default needs({
    props: [ 'name' ],
    action: ping,
})(MyComponent);

API

const binder = needs(bindings);

Returns a new binder method which, when called with a component, will return the component wrapped with the configured bindings. This method is compatible with the Redux compose method.

  • bindings (required) - an array containing bindings

Bindings

Simple bindings

Simple bindings will trigger an action only once: when the component is mounted.

To add a simple binding just add an action creator to the array of bindings. When the component is mounted the action creator will be called with this.props and the resulting action will be dispatched.

Go to the example.

Complex bindings

Complex bindings will trigger an action when the component is mounted and again when one or more of the bound properties change.

To add a complex binding add an object to array of bindings with two properties:

  • action - the action creator
  • props - an array of strings describing the properties of the component to watch

The prop field can contain nested properties. For example; given the following object, the c property with a value of 3 can be bound to using a[0].b.c:

{
  "a": [
    { "b": { "c": 3 } },
    { "b": { "c": 4 } }
  ],
  "d": 5
};

When binding to specific values, the action creator will be called with a subset of this.props matching the bound property paths. In the case of the previous example, this would mean the action creator would be called with the follwing object:

{
  "a": [
    { "b": { "c": 3 }
  ]
}

Note: the action creators will sometimes be called even if the action will not be dispatched. As this could potentially be every time componentWillUpdate is called on your component, your action creators should be lightweigth methods.

Go to the example.

Installation

With npm installed, run

$ npm install redux-needs

Or with yarn installed, run

$ yarn add redux-needs

Peer dependencies

This library uses the following peer dependencies, which will probably already be included in your project if it's uses Redux and React:

  • react: 15.5.x
  • react-redux: 5.x.x
  • redux: 3.7.x

License

The redux-needs package is distributed under the 3-Clause BSD License. Check the LICENSE file for details.