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

restrux

v1.2.1

Published

observable redux connector

Downloads

12

Readme

restrux

Observable bindings to redux or redux-like react context.

So.. why do we need that

Redux is great, however all connectors recomputes the selection on each state change (even completely unrelated to connected component). By increasing number of connnected components, each state update becomes more expensive. Also sometimes it may be quite tricky to write a good comparing sollution for your selector, or you may just forget to add shallowCompare when using selector hook. The issue is that performance bugs are not easy ones to catch, which may make your app to perform bad on slower devices. Restrux aims to remove this downside, by streaming parts of your state to target components. This will make components been called lazily when there source data has changed, instead of requesing the state on each store change.

Installation

npm i -S restrux

Usage

Define selectors

import { defineSelector } from 'restrux';

const selectUsers = ({ users }) => users;

const selectCurrentUserId = ({ currentUserId }) => currentUserId;

const selectedUser = defineSelector(
  selectUsers,
  selectCurrentUserId,
  (users, currentUserId) => users[currentUserId],
);

The selectedUser object, is just a spec, that will be later fullfilled to a selector driver. It's designed this way, so you can reuse it for both stream based and classic selectors (for example to use it in redux-saga).

Wrap your app with provider

import { Provider } from 'restrux';

const AppWrapper = () => (
  <Provider store={store}>
    <App />
  </ Provider>
);

Use selector in your component

import { useMappedStoreState } from 'restrux';

const UserPanel = React.memo(() => {
  const user = useMappedStoreState(selectedUser);
  return (
    <div>
      {user.name}
    </div>
  );
});

Use direct manipulation

const UserPanel = React.memo(() => {
    const stream = useMappedStoreStateStream(selectLoadingProgress);
    const ref = useRef(null);
    useEffect(() => {
        stream.subscribe(progress) => {
            if (ref.current) {
                ref.current.style.opacity = progress;
            }
        });
    }, [stream]);
    
    return (
        <data
          ref={ref}
        >
          Loading...
        </data>
    );
});