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

@samsch/subscribe-to

v0.0.1

Published

A React Higher-order Component which subscribes to a prop to update on changes.

Downloads

2

Readme

subscribeTo

The subscribeTo React HoC wraps a component and listen for changes on a subscribable prop. When the subscription fires, the HoC forces a new render of the wrapped component. Designed to work with samsch/subscribe-store.

Installation

Install into your project with npm i @samsch/subscribe-to (for Node.js), or npm i -D @samsch/subscribe-to (for Webpack/Browserify or other bundled projects).

Use

The @samsch/subscribe-to module has a single default export, which is the subscribeTo function.

To use subscribeTo, you pass it a function for retrieving a subscribable from props, returning a function, and then pass the component you want to wrap, returning a new component.

  • subscribeTo: <(props => store)> => <Component: react-component> => Component: react-component

subscribeTo expects that the subscribable has two methods: store.subscribe(<listener: Function>) and store.unsubscribe(<listener: Function>). Anytime the listener function which subscribeTo passes is called by the store, the component will re-render.

The stores created by samsch/subscribe-store follow this pattern correctly, and the source of the project can be used as an example of a valid store implementation.

Basic example

// createStore from '@samsch/susbcribe-store'
const store = createStore({ data: 0 });

const SomeComponent = props => (
  <span>Data: {props.store.state.data}</span>
);

const SubscribedComponent =
  subscribeTo(props => props.store)(SomeComponent);

ReactDOM.render(<SubscribedComponent store={store} />, rootElement);

ES support

This library is compiled with Babel to support IE11 and last 2 Chrome, Edge, Firefox, and Safari. Publically, it expects ES6 methods/objects to exist (natively or polyfilled). Realistically, you could test it and find that it might work in a pure ES5 environment.

If a case is found which doesn't work in pure ES5 environments, and it doesn't require drastic changes or much uglier code, I'll pull those changes in.

Getting help

You can frequently find me (samsch) hanging out in ##javascript, #Node.js, and #reactjs on Freenode, especially during US working hours. This is a small library, so it's likely someone else could help you as well if you point them at the source file and your code.

Contributing

Code is formatted to the local prettier/eslint config.

Run tests once with npm test, or continuously with npm test -- --watch.

The projects builds with npm run build, which is also called on pre-publish.