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

luffie

v0.3.0

Published

A state management library for React

Downloads

168

Readme

Build Status Coverage Status

A state management library for React.

If you need a simple way to manage your application's state without needing to rewrite a lot of code, maybe you like Luffie.

You can keep your state centralized at our Store and create functions that alter the Store State. Everytime the state gets updated, all components plugged into it are rendered automatically.

In Luffie, you need two steps to do that:

How to install

npm install --save luffie

or

yarn add luffie

How to use

import { createStore, plug } from "luffie"

The store is a place where you keep the data that you need to access across you application. Usually you will have a Store for each Page or Shared Resource that you need to keep in your application's memory.

1. Initialize your Store


const initialState = {
  ...yourInitialData
}

const { updateState, getCurrentState, state$ } = createStore(initialState);

2. Export your State Stream

const yourState$ = state$;

export { yourState$ }

3. Create actions that change your store

const changeTotal = (quantity: number) => {
  updateState({ total: 10 })
}

When you call updateState, your new data will be merged with the current data stored and a new state will be forwarded for all Components/Subscribers of you Store.

The other side of the coin is the UsePlug Hook. This way you can Plug your component into your newly created Store and at each change, the store data update your component's state.

const TestComponent = ({ name, total }) => {
  const state = useStream(state$)
  return (
    <div>
      <h1 data-testid="name">{name}</h1>
      <p data-testid="total">Total: {total}</p>
      <p data-testid="changed">The store was{changed ? '' : `n't`} changed.</p>
    </div>
  )
}

Use Luffie like this if your React doesn't support Hooks If you use a older version of React without Hooks, you can use the Plug HOC to connect your component with you store state following the steps described below:

1. Create your Container

const TestComponent = (props) => {
  const { total, changed, name } = props;
  return (
    <div>
      <h1 data-testid="name">{name}</h1>
      <p data-testid="total">Total: {total}</p>
      <p data-testid="changed">The store was{changed ? '' : `n't`} changed.</p>
    </div>
  )
}

2. Create your StreamToProp constant.

This stream receives your parent's component Prop, and this way you can merge it with your Store's State.

const streamToProp = (props) => {
  return of(props).pipe(
    combineLatest(state$),
    map(([props, state]) => {
      const data = {
        name: props.name,
        ...state
      }
      return data;
    })
  );
}

3. Plug!

const PluggedTestComponent = plug(streamToProp)(TestComponent);

Future Plans

  • Make RxJs optional
  • Use React Hooks instead of a PureComponent inside Plug's HOC