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

compelem-store

v0.1.1

Published

A store for CompElem

Readme

CompElem Store

A state management for CompElem.

Installation

npm install compelem-store

Usage

defineStore

import { defineStore } from 'compelem-store';

// 完整形态:state / getters / actions
const counterStore = defineStore({
  id: 'counter',
  state: () => ({ count: 0, step: 1 }),
  getters: {
    double: (state) => state.count * 2,
  },
  actions: {
    inc() { this.count += this.step },   // this 即 store facade,直接读写 state
    setStep(step: number) { this.step = step },
  },
});

// 轻量形态:只给 state —— defineStore 直接返回可读写的 facade(无工厂、无调用括号)
const themeStore = defineStore({
  id: 'theme',
  state: () => ({ mode: 'light' }),
});

Use in Component

import { CompElem, tag, h } from 'compelem';
import { useStore } from 'compelem-store';

@tag('counter-view')
export class CounterView extends CompElem {
  render() {
    const store = counterStore;   // render 内读取即自动订阅,无需任何注册
    return h`<span>${store.count} / ${store.double}</span>
             <button @click=${() => store.inc()}>+1</button>`;
  }
}

在 render 之外(如 connectedCallback、事件回调中初始化)需要显式接入时:

const store = useStore('counter', this);   // 或 useStore(counterStore, this)
// 或 counterStore.connect(this);

Subscribe / Batch

const unsubscribe = store.subscribe((mutation, snapshot) => {
  console.log(mutation.key, mutation.oldValue, '→', mutation.newValue);
});
store.patch({ count: 100 });

API

| API | 说明 | |---|---| | defineStore(options) | 完整 store(state/getters/actions),同 id 单例;直接返回 facade 本体(轻量场景只给 state 即可) | | getStoreById(id) | 按 id 取已注册 facade(undefined 表示未定义) | | disposeStore(id) / resetStores() | 从注册表摘除 / 清空全部 store(测试隔离用) | | useStore(store, comp) | 显式接入订阅(render 内读取已自动订阅,此形式用于 render 之外);store 参数支持 facade / id 字符串,返回 facade | | store.state | 响应式 state 代理 | | store.patch(partial) | 批量更新 | | store.reset() | 用 state() 工厂重新初始化(多余键移除) | | store.subscribe(cb) | 手动监听,返回退订函数 | | store.connect(comp) / disconnect(comp) | 手动接入/解除组件订阅 |

Development

npm install
npm run dev          # demo(内置 ?selftest=1 自动化自检)
npm run typecheck    # tsc --noEmit
npm run build        # 库构建(ESM + UMD + d.ts + sourcemap)

License

MIT