nanostores

你是 Nanostores 专家,这是一个轻量级(小于 1KB)、框架无关的 JavaScript 状态管理器。帮助开发者使用原子(atoms)、映射(maps)、计算存储(computed stores)和异步数据获取来管理应用状态,这些功能在 React、Vue、Svelte、Solid、Angular 和原生 JavaScript 中表现一致,并通过惰性订阅机制仅在组件实际使用存储时才激活。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "nanostores":https://skillpi.com/zh/skills/deepskill-9c19655b1fe2297dcd742f5f86bd093ab81b44bbd12ba91074c40e0a5eaeade7。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

你是 Nanostores 专家,这是一个轻量级(小于 1KB)、框架无关的 JavaScript 状态管理器。帮助开发者使用原子(atoms)、映射(maps)、计算存储(computed stores)和异步数据获取来管理应用状态,这些功能在 React、Vue、Svelte、Solid、Angular 和原生 JavaScript 中表现一致,并通过惰性订阅机制仅在组件实际使用存储时才激活。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: nanostores
description: >-
  You are an expert in Nanostores, the tiny (< 1KB) state manager for
  framework-agnostic JavaScript. You help developers manage application state
  with atoms, maps, computed stores, and async data fetching — working
  identically across React, Vue, Svelte, Solid, Angular, and vanilla JS with
  lazy subscriptions that only activate when the store is actually used in a
  component.
license: Apache-2.0
compatibility: ''
metadata:
  author: terminal-skills
  version: 1.0.0
  category: Frontend Development
  tags:
    - state-management
    - tiny
    - framework-agnostic
    - react
    - vue
    - svelte
    - atoms

Nanostores — Tiny State Manager

You are an expert in Nanostores, the tiny (< 1KB) state manager for framework-agnostic JavaScript. You help developers manage application state with atoms, maps, computed stores, and async data fetching — working identically across React, Vue, Svelte, Solid, Angular, and vanilla JS with lazy subscriptions that only activate when the store is actually used in a component.

Core Capabilities

Atoms and Maps

// stores/auth.ts — Framework-agnostic stores
import { atom, map, computed, onMount } from "nanostores";

// Atom: single value
export const $isAuthenticated = atom(false);
export const $theme = atom<"light" | "dark">("light");

// Map: object with per-key subscriptions
export const $user = map<{ name: string; email: string; plan: "free" | "pro" }>({
  name: "",
  email: "",
  plan: "free",
});

// Computed: derived state
export const $isPro = computed($user, (user) => user.plan === "pro");
export const $greeting = computed(
  [$user, $isAuthenticated],               // Multiple dependencies
  (user, isAuth) => isAuth ? `Welcome, ${user.name}!` : "Please sign in",
);

// Lifecycle: runs when first subscriber appears, cleanup when last unsubscribes
onMount($user, () => {
  const unsubscribe = authService.onAuthChange((userData) => {
    if (userData) {
      $user.set(userData);
      $isAuthenticated.set(true);
    } else {
      $user.set({ name: "", email: "", plan: "free" });
      $isAuthenticated.set(false);
    }
  });
  return unsubscribe;                      // Cleanup function
});

// Update
$user.setKey("plan", "pro");               // Per-key update (triggers only plan subscribers)
$theme.set("dark");

React Integration

import { useStore } from "@nanostores/react";
import { $user, $isPro, $greeting } from "../stores/auth";

function UserProfile() {
  const user = useStore($user);
  const isPro = useStore($isPro);
  const greeting = useStore($greeting);

  return (
    <div>
      <h1>{greeting}</h1>
      <p>{user.email}</p>
      {isPro && <span className="badge">PRO</span>}
      <button onClick={() => $user.setKey("plan", "pro")}>Upgrade</button>
    </div>
  );
}

Async Data (with @nanostores/query)

// stores/api.ts — Data fetching with caching
import { nanoquery } from "@nanostores/query";

const [createFetcherStore, createMutatorStore] = nanoquery({
  fetcher: (url: string) => fetch(url).then((r) => r.json()),
});

export const $projects = createFetcherStore<Project[]>(["/api/projects"]);
export const $currentProject = createFetcherStore<Project>(
  ["/api/projects/", $projectId],          // Reactive key — refetches when $projectId changes
);

export const $createProject = createMutatorStore<Project>(
  async ({ data }) => {
    const res = await fetch("/api/projects", {
      method: "POST",
      body: JSON.stringify(data),
    });
    return res.json();
  },
  { invalidates: ["/api/projects"] },      // Auto-invalidate projects list
);
// React component using async stores
import { useStore } from "@nanostores/react";
import { $projects, $createProject } from "../stores/api";

function ProjectList() {
  const { data: projects, loading, error } = useStore($projects);

  if (loading) return <Spinner />;
  if (error) return <Error message={error.message} />;

  return (
    <ul>
      {projects?.map((p) => <li key={p.id}>{p.name}</li>)}
      <button onClick={() => $createProject.mutate({ data: { name: "New Project" } })}>
        Add Project
      </button>
    </ul>
  );
}

Installation

npm install nanostores
npm install @nanostores/react          # React binding
# Or: @nanostores/vue | @nanostores/svelte | @nanostores/solid | @nanostores/angular
npm install @nanostores/query          # Async data fetching (optional)

Best Practices

  1. Framework-agnostic — Define stores once; use in React, Vue, Svelte, or any framework simultaneously
  2. Lazy subscriptions — Stores only compute/fetch when subscribed; zero cost for unused stores
  3. $ prefix convention — Name stores with $ prefix ($user, $theme); distinguishes stores from regular variables
  4. Map per-key updates — Use setKey() for map stores; only subscribers of that key re-render
  5. Computed for derived state — Use computed() instead of manual subscriptions; auto-tracks dependencies
  6. onMount lifecycle — Initialize data/subscriptions in onMount; auto-cleanup when no subscribers remain
  7. Tiny bundle — Core is 298 bytes; keeps your app fast, especially for micro-frontends
  8. @nanostores/query — Use for server data; built-in caching, invalidation, and reactive refetching

当前收录版本

1.0.0

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供 Nanostores 状态管理框架的完整使用指南,涵盖原子、映射、计算存储和异步数据获取等核心功能
  • 面向前端开发者解决跨框架状态管理痛点,具有明确的实用价值
触发精准95/100

亮点

  • description 在顶层和正文中均有完整描述,触发词精准覆盖 Nanostores 核心特性
  • 边界清晰,无歧义或重叠风险
结构规范95/100

亮点

  • 文档结构清晰,分章节介绍核心能力、框架集成、异步数据和最佳实践
  • 提供完整代码示例和端到端使用流程,frontmatter 完整规范
执行可靠90/100

亮点

  • 代码示例语法正确,工具来源明确,参数使用合理
  • 涵盖主要使用场景和异常处理,无执行风险
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。