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

colmado

v1.0.8

Published

Uncompliacted store and minimal flux implementation with react contexts

Downloads

4

Readme

Colmado

Colmado is an uncomplicated and minimal flux architecture implementation on top of react contexts.

It proposes a singleton store with modules. Each module has a warehouse, where the data is stored, and a reducer, where actions are defineds. Colmado will create your store and dispatch your actions (change events) to the warehouses. Yes, it's like redux, but home made.

Insted of a framework, it's an architectonic proposal with two helper functions: createStore and useStore. The source code is only 70 lines: easy to read, easy to understand, easy to hack.

Install

npm i --save colmado

Code structure

You can use colmado in your own way –all together in a flat file or scattered throughout your components–, but to ensure scalability and modularity, we propose the following directory structure.

├── index.js # Your app root
├── store # Store root directory
│   ├── index.js # Your store instance
│   ├── greetings # Store module. Open a new folder for each module
│   │   ├── index.js # The module instance
│   │   └── reducer.js # Optional, but if your reducer is getting bigger, you can place your actions in a separate file

Usage

The store

To start with colmado, you have to create your store. Let's do it

import { createStore } from "colmado";
const Store = createStore();

The store modules

Easy! But your store is empty. So, lets create one module.

const myModule = {
  name: "names",
  Component: ({ Warehouse, children }) => {
    const [state, setState] = useState();
    return <Warehouse value={[state, setState]}>{children}</Warehouse>;
  },
};

const storeModules = [myModule];
const Store = createStore(storeModules);

Now you have your warehouse where you can store your data, but nobody is dispatching orders.

Reducers

The store isolate your state from the rest of your application into its warehouses and only allows you to place orders to the dispatcher. To be able to dispatch orders, you have to define your reducer. So, let's go.

const myModule = {
  name: "names",
  Component: ({ Warehouse, children }) => {
    const [state, setState] = useState("Garfield");
    return <Warehouse value={[state, setState]}>{children}</Warehouse>;
  },
  reducer: ({ state, action, payload }) => {
    switch (action) {
      case "SET_NAME":
        return payload;
    }
  },
};

Hook and dispatch

And your colmado store is ready to open its doors. You only have to wrap your react components with the store and use the useStore hook to access the warehouse data and the dispatcher.

import { useStore } from "colmado";
import Store from "./store";

function SayHelloTo() {
  const [store, dispatch] = useStore();

  function setName(ev) {
    const value = ev.currentTarget.name;
    dispatch({
      action: "SET_NAME",
      payload: value,
    });
  }

  return (
    <>
      <select onChange={setName}>
        <option value="Gargamel">Gargamel</option>
        <option value="Suneo">Suneo</option>
      </select>
      <p>Hello, {store.name}!</p>
    </>
  );
}

function App() {
  return (
    <Store>
      <SayHelloTo />
    </Store>
  );
}