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

@resuspend/redux

v1.0.0-rc11

Published

<!-- markdownlint-disable-next-line --> <p align="center"> <a href="https://resuspend.js.org" rel="noopener" target="_blank"><img height="100" src="https://gist.githubusercontent.com/json2d/ffbf9ae39c31a3e1ea1c84277e157f1d/raw/f8e8cba55285fc33c607374892

Downloads

3

Readme

this integration of the core resuspend library w/ the Redux state management library provides a <ConnectedSuspension/> component which uses selectors, actions, and store state as the basis for implementing your suspension logic

npm node npm npm

getting started

To install the latest stable version:

npm i -s resuspend @resuspend/redux

basic example

here's a simple example of Redux based suspension logic.

starting with a base component:

import React from "react";

export const UserProfile = (props) => (
  <div>
    <h1>{props.user.name}</h1>
    <pre>@{props.user.id}</pre>
    <p>{props.user.status}</p>
    <button onClick={props.onRefresh}>Refresh</button>
  </div>
);

set up a typical connection between the base component and the store state:

import React, { useCallback } from "react";

// action creators
const setUser = (payload) => ({ type: 'SET_USER', payload });
const refreshUser = (payload) => ({ type: 'REFRESH_USER', payload });

// selectors
const getUserWithId = (userId) => (state) => state.userById[userId];

export const ConnectedUserProfile = (props) => {
  const getUser = useCallback(getUserWithId(props.userId), [props.userId]);

  const user = useSelector(getUser);
  const dispatch = useDispatch();

  const onRefresh = useCallback(() => {
    dispatch(refreshUser({ userId: props.userId }));
  }, [dispatch, props.userId]);

  return <UserProfile user={user} onRefresh={onRefresh} />;
};

then finally, you can define the suspension logic w/ selectors and assign it to the props of a <ConnectedSuspension> component:

import React, { useCallback } from "react";
import { ConnectedSuspension } from '@resuspend/redux';

import * as mocks from "../mocks"; // mock users for simulating fetch below

// activation status via a store selector
const noUserWithId = (userId) => (state) => !getUserWithId(userId)(state);

// activation effect via an action selector
const fetchUserWithId = (userId) => (state) => /* thunk you! */ (dispatch) => {
  // simulate fetch
  setTimeout(() => {
    const user = mocks.users[userId];
    dispatch(setUser({ user }));
  }, 2000);
};

export const SuspendableConnectedUserProfile = (props) => {
  const noUser = useCallback(noUserWithId(props.userId), [props.userId]);
  const fetchUser = useCallback(fetchUserWithId(props.userId), [props.userId]);

  return (
    <ConnectedSuspension activeSelector={noUser} onActiveSelector={fetchUser}>
      <ConnectedUserProfile {...props} />
    </ConnectedSuspension>
  );
};

try it out now in a live editor via CodeSandbox ✨