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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@einfach/core

v0.2.18

Published

Lightweight Jotai-inspired atomic state management core

Readme

@einfach/core

轻量级、受 Jotai 启发的 atom 状态管理核心库(框架无关)。

安装

npm install @einfach/core
# or
pnpm add @einfach/core

基本用法

创建 Atom

import { atom, createStore } from '@einfach/core'

// 基础 atom
const countAtom = atom(0)

// 派生 atom(只读)
const doubleAtom = atom((get) => get(countAtom) * 2)

// 可写派生 atom
const incrementAtom = atom(
  (get) => get(countAtom),
  (get, set, step: number) => set(countAtom, get(countAtom) + step)
)

使用 Store

const store = createStore()

// 读取
store.getter(countAtom) // 0

// 写入
store.setter(countAtom, 1)
store.getter(countAtom) // 1

// 订阅
const unsub = store.sub(countAtom, () => {
  console.log('count changed:', store.getter(countAtom))
})

// 取消订阅
unsub()

// 清空 store
store.clear()

异步 Atom

const userAtom = atom(async (get) => {
  const id = get(userIdAtom)
  const res = await fetch(`/api/users/${id}`)
  return res.json()
})

API

核心

| API | 说明 | |-----|------| | atom(initialValue) | 创建基础 atom | | atom(readFn) | 创建只读派生 atom | | atom(readFn, writeFn) | 创建可写派生 atom | | createStore() | 创建 store 实例 | | getDefaultStore() | 获取默认 store 单例 |

Store 方法

| 方法 | 说明 | |------|------| | store.getter(atom) | 读取 atom 值 | | store.setter(atom, ...args) | 写入 atom 值 | | store.sub(atom, listener) | 订阅 atom 变化,返回取消订阅函数 | | store.clear() | 清空 store |

工具函数

| API | 说明 | |-----|------| | selectAtom(atom, selectorFn, equalFn?) | 创建带选择器的派生 atom | | atomWithCompare(initialValue, equalFn) | 创建带自定义比较的 atom | | atomWithRefresh(readFn) | 创建可刷新的 atom | | atomWithLazyRefresh(readFn) | 创建懒加载可刷新 atom | | createAsyncParamsAtom(asyncFn) | 创建接收参数的异步 atom | | createUndoRedo(atom) | 创建撤销/重做系统 | | incrementAtom(atom, derivations) | 创建带派生计算的 atom | | createCacheStom(atomFn, options?) | 创建 LRU 缓存 atom 工厂 | | memo(weakKey, fn) | 基于 WeakKey 缓存值 |

许可证

MIT