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

pooppy

v1.0.5

Published

A state management portfolio for personal use only

Downloads

9

Readme

pooppy

A state management portfolio for personal use only

⚠️:

need 16.8.0-alpha.1 for react and react-dom, then use hooks happy!

This is a project that is a combination of some on-site projects or ideas in the issue.

The main purpose is to make it easier for me to use in the project without introducing multiple libraries.

Of course, I will gradually combine these excellent libraries to do some interesting combinations.

how to use

name is pooppy!!!

yarn add pooppy

let's do it

only use createContainer:

import { createContainer } from "pooppy";

function useCounter() {
  const [count, updater] = React.useState(0);
  const increment = (dep = 1) => {
    updater(count + 1);
  };

  const decrement = (dep = 1) => {
    updater(count - 1);
  };

  const asyncIncrement = (dep = 1) => {
    setTimeout(() => {
      updater(count + 1);
    }, 2000);
  };

  return React.useMemo(
    () => ({
      count,
      increment,
      decrement,
      asyncIncrement
    }),
    [count]
  );
}

const { Provider, Context } = createContainer(useCounter);

function Count() {
  const { count } = React.useContext(Context);
  return <span>{count}</span>;
}

function Button() {
  const { increment, decrement, asyncIncrement } = React.useContext(Context);
  return (
    <div>
      <button onClick={increment}> + </button>
      <button onClick={decrement}> - </button>
      <button onClick={asyncIncrement}> async + </button>
    </div>
  );
}

function App() {
  return (
    <div className="App">
      <Provider>
        <Count />
        <Button />
      </Provider>
    </div>
  );
}

demo01

use immer and nest:

import { useImmer, nest, createContainer } from "pooppy";

let uuid = () =>
  Math.random()
    .toString(16)
    .slice(3);

function todoContainer() {
  const [todos, updater] = useImmer([
    {
      msg: "this is a default todos",
      key: "default",
      finish: false
    }
  ]);

  const addTodos = msg => {
    updater(draft => {
      draft.push({
        msg,
        key: uuid(),
        finish: false
      });
    });
  };

  const deleteTodos = uuid => {
    updater(draft => {
      const index = draft.findIndex(item => item.key === uuid);
      if (index >= 0) draft.splice(index, 1);
    });
  };

  const finished = uuid => {
    updater(draft => {
      draft.forEach(todo => {
        if (todo.key === uuid && todo.finish === false) {
          todo.finish = true;
        }
      });
    });
  };

  return React.useMemo(
    () => ({
      todos,
      addTodos,
      deleteTodos,
      finished
    }),
    [todos]
  );
}

const { Provider, Context } = createContainer(todoContainer);

function ToDos() {
  const { todos } = React.useContext(Context);
  return (
    <ul>
      {todos.map(todo => {
        return (
          <li key={todo.key}>
            <span>
              {todo.msg} | {todo.finish ? "done" : "undone"}
            </span>
            <Button uuid={todo.key} />
          </li>
        );
      })}
    </ul>
  );
}

function AddTodo() {
  const { addTodos } = React.useContext(Context);
  const [msg, setMsg] = React.useState("");
  const handleOnchange = e => {
    setMsg(e.target.value);
  };
  return (
    <>
      <input onChange={handleOnchange} value={msg} />
      <button onClick={() => addTodos(msg)}>add</button>
    </>
  );
}

function Button(props) {
  const { deleteTodos, finished } = React.useContext(Context);
  return (
    <>
      <button onClick={() => deleteTodos(props.uuid)}> delete </button>
      <button onClick={() => finished(props.uuid)}> finish </button>
    </>
  );
}

function App() {
  return (
    <div className="App">
      <Provider>
        <ToDos />
        <AddTodo />
      </Provider>
    </div>
  );
}

demo02

about nest

// just like this
const { Provider } = createContainer(someCounter)

const NestComponent = nest(Provider, SomeChildUnStateComponent)

changelog

  • [x] 2019-3-12 add useWhyDidYouUpdate Hooks, click to see use demo.

Reference

1. nest 2. immer 3. constate 4. use-immer