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

jotaish

v1.0.3

Published

Better Jotai DX with Jotaish 🃏

Downloads

6

Readme

Better Jotai DX with Jotaish

Get started

pnpm i jotaish

The Problem

In Short, as scale of number of atoms becomes larger, managing them becomes more harder.

Large scale problem list

  1. When using atom, you might have to declare and naming the state and setter's name everytime using it.
  2. Custom hook logic might reduce this effort. But that means each atom require own custom hook. It is not DRY.
  3. You should remember declared atom's name to import it with vscode autocompletion.

The Solution

Consistent name and import with magical ✨autocompletion✨

  1. Categorize atoms by usage (📢 user requirements)
  2. Autocomplete atom's name
  3. Autocomplete atom-state-setter's name

Adoptation

Without Jotaish🃏

// ❌ import each atoms, name state-setter
import { useAtom } from "jotai";
import { count } from "@atoms/count";

const [count, setCount] = useAtom(count);

// ❌ use custom hook for each atoms
import { useCountHook } from "@atoms/count";

const { count, setCount } = useCountHook();

With Jotaish🃏

// ✅  use magical ✨autocompletion✨.
import { $, useStore } from "@atoms/index";

const { Count, setCount } = useStore($("count"));

$ function autocompletes all atom's name

How to use

STEP1: Make Atom Store

at */atom/countAtoms.ts

import { atom } from "jotai";

const count = atom(1);
const isCountEven = atom((get) => get(count) % 2 === 0);

at */atom/index.ts

const Store = {
    count,
    isCountEven,
} as const; // ✅ It is much safer with const-assertion

const assertion 🚩

STEP2: Make $ function and export $, useStore function in one file

at */atom/index.ts

import { count, isCountEven } from "./countAtoms";
import { getStore, useStore } from "jotaish";

const Store = {
    count,
    isCountEven,
} as const;

const $ = getStore(Store); // ✅ You can choose diffrent name like _, _s!
export { $, useStore };

STEP3: Use atoms in the component

import { useStore, $ } from "@atoms/index";

const Counter = () => {
    const { Count, setCount } = useStore($("count"));
    const { IsCountEven, setIsCountEven } = useStore($("isCountEven"));

    return (
        <div>
            <h1>Count: {Count}</h1>
            <h2>{IsCountEven ? "Even" : "Odd"}</h2>

            <button onClick={() => setCount((c) => c + 1)}>Plus 🔺</button>
            <button onClick={() => setCount((c) => c - 1)}>Minus 🔻</button>
        </div>
    );
};

Return value according to Atom type

All Return value is 🃏-fully-jotai-typed-🃏

CASE1. Primitive, Read-Write Atom

// primitive 🟩
const count = atom(1);

// read-write 🟩
const increaseCountTextAndAction = atom(
    (get) => `count is: ${get(count)}`,
    (get, set) => set(count, get(count) + 1)
);

🔔 Returns state & setter & atom itself

const { Count, setCount, atomOfCount } = useStore($("count"));

CASE2. Read Only Atom

// read-only 🟨
const isEven = atom((get) => get(count) % 2 === 0);

🔔 Returns state & atom itself

const { IsEven, atomOfIsEven } = useStore($("isEven"));

CASE3. Write Only Atom

// write-only 🟦
const updateCount = atom(
    null, // for specifying writing atom
    (get, set, newCount: number) => set(count, newCount)
);

🔔 Returns state & setter & atom itself

But state = null, Just ignore it and don't destruct.

const { setUpdateCount, atomOfUpdateCount } = useStore($("updateCount"));

Size


# ✅ ESM ======================================
dist/jotaish.es.js   0.31 KiB / gzip: 0.22 KiB

# ✅ UMD ======================================
dist/jotaish.umd.js   0.54 KiB / gzip: 0.35 KiB

LICENSE

MIT