@violetflux/kerros 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.de.md +7 -0
- package/README.es.md +7 -0
- package/README.fr.md +7 -0
- package/README.ja.md +7 -0
- package/README.ko.md +7 -0
- package/README.md +8 -0
- package/README.zh-CN.md +7 -0
- package/package.json +6 -3
- package/skills/kerros/SKILL.md +139 -0
- package/skills/kerros/agents/openai.yaml +4 -0
package/README.de.md
CHANGED
|
@@ -21,6 +21,13 @@ Kerros lässt React-State dort, wo er natürlich hingehört: in Hooks und unter
|
|
|
21
21
|
- Stores lassen sich über einseitige Abhängigkeiten komponieren
|
|
22
22
|
- Unterstützt React 17, 18 und 19
|
|
23
23
|
|
|
24
|
+
> [!TIP]
|
|
25
|
+
> **Mit Codex installieren**: Füge diesen Satz in Codex ein, um Abhängigkeit und Projekt-Skill gemeinsam zu installieren.
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
Installiere @violetflux/kerros mit dem Paketmanager dieses Projekts und führe danach npx skills add violetflux/kerros --skill kerros --agent codex -y aus.
|
|
29
|
+
```
|
|
30
|
+
|
|
24
31
|
## Store erstellen
|
|
25
32
|
|
|
26
33
|
```tsx
|
package/README.es.md
CHANGED
|
@@ -21,6 +21,13 @@ Kerros mantiene el estado de React donde pertenece de forma natural: dentro de H
|
|
|
21
21
|
- Los Stores se componen mediante dependencias unidireccionales
|
|
22
22
|
- Compatible con React 17, 18 y 19
|
|
23
23
|
|
|
24
|
+
> [!TIP]
|
|
25
|
+
> **Instalar con Codex**: pega esta frase en Codex para instalar la dependencia y el Skill del proyecto a la vez.
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
Instala @violetflux/kerros con el gestor de paquetes del proyecto y después ejecuta npx skills add violetflux/kerros --skill kerros --agent codex -y.
|
|
29
|
+
```
|
|
30
|
+
|
|
24
31
|
## Crear un Store
|
|
25
32
|
|
|
26
33
|
```tsx
|
package/README.fr.md
CHANGED
|
@@ -21,6 +21,13 @@ Kerros conserve l'état React là où il se trouve naturellement : dans les Hook
|
|
|
21
21
|
- Les Stores se composent grâce à des dépendances unidirectionnelles
|
|
22
22
|
- Compatible avec React 17, 18 et 19
|
|
23
23
|
|
|
24
|
+
> [!TIP]
|
|
25
|
+
> **Installer avec Codex** : collez cette phrase dans Codex pour installer à la fois la dépendance et le Skill du projet.
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
Installe @violetflux/kerros avec le gestionnaire de paquets du projet, puis exécute npx skills add violetflux/kerros --skill kerros --agent codex -y.
|
|
29
|
+
```
|
|
30
|
+
|
|
24
31
|
## Créer un Store
|
|
25
32
|
|
|
26
33
|
```tsx
|
package/README.ja.md
CHANGED
|
@@ -21,6 +21,13 @@ Kerros は React の状態を Hook の中、Provider の下という自然な場
|
|
|
21
21
|
- 一方向の依存関係で Store を合成可能
|
|
22
22
|
- React 17、18、19 をサポート
|
|
23
23
|
|
|
24
|
+
> [!TIP]
|
|
25
|
+
> **Codex でインストール**:次の一文を Codex に貼り付けると、依存関係とプロジェクト Skill をまとめてインストールできます。
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
このプロジェクトのパッケージマネージャーで @violetflux/kerros をインストールし、npx skills add violetflux/kerros --skill kerros --agent codex -y を実行してください。
|
|
29
|
+
```
|
|
30
|
+
|
|
24
31
|
## Store を作成する
|
|
25
32
|
|
|
26
33
|
```tsx
|
package/README.ko.md
CHANGED
|
@@ -21,6 +21,13 @@ Kerros는 React 상태를 Hook 안과 Provider 아래라는 자연스러운 위
|
|
|
21
21
|
- 단방향 의존성을 통한 Store 조합
|
|
22
22
|
- React 17, 18, 19 지원
|
|
23
23
|
|
|
24
|
+
> [!TIP]
|
|
25
|
+
> **Codex로 설치**: 아래 문장을 Codex에 붙여넣으면 의존성과 프로젝트 Skill을 함께 설치합니다.
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
현재 프로젝트의 패키지 매니저로 @violetflux/kerros를 설치한 다음 npx skills add violetflux/kerros --skill kerros --agent codex -y를 실행하세요.
|
|
29
|
+
```
|
|
30
|
+
|
|
24
31
|
## Store 만들기
|
|
25
32
|
|
|
26
33
|
```tsx
|
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
<a href="https://www.npmjs.com/package/@violetflux/kerros"><img src="https://img.shields.io/npm/v/@violetflux/kerros?color=7c3aed" alt="npm version" /></a>
|
|
19
19
|
<a href="https://github.com/violetflux/kerros/actions/workflows/ci.yml"><img src="https://github.com/violetflux/kerros/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
|
|
20
20
|
<a href="https://bundlephobia.com/package/@violetflux/kerros"><img src="https://img.shields.io/bundlephobia/minzip/@violetflux/kerros?label=gzip&color=2563eb" alt="minified gzip size" /></a>
|
|
21
|
+
<a href="https://github.com/violetflux/kerros/tree/main/skills/kerros"><img src="https://img.shields.io/badge/Agent_Skill-Kerros-7c3aed" alt="Kerros Agent Skill" /></a>
|
|
21
22
|
<a href="https://github.com/violetflux/kerros/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@violetflux/kerros" alt="MIT license" /></a>
|
|
22
23
|
</p>
|
|
23
24
|
|
|
@@ -25,6 +26,13 @@ Kerros is a lightweight way to share state between React components.
|
|
|
25
26
|
|
|
26
27
|
Write a Store the same way you write a custom Hook. When local state needs to be shared, pass it to `createStore`, mount its Provider, and let each component select what it needs.
|
|
27
28
|
|
|
29
|
+
> [!TIP]
|
|
30
|
+
> **Install with Codex** — copy and paste this sentence into Codex to install both the dependency and the project Skill:
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
Install @violetflux/kerros with this project's package manager, then run npx skills add violetflux/kerros --skill kerros --agent codex -y.
|
|
34
|
+
```
|
|
35
|
+
|
|
28
36
|
## Quick start
|
|
29
37
|
|
|
30
38
|
### Create a Store
|
package/README.zh-CN.md
CHANGED
|
@@ -18,6 +18,13 @@ Kerros 是一个在 React 组件间共享状态的轻量方案。
|
|
|
18
18
|
|
|
19
19
|
你怎么写 custom Hook,就可以怎么写 Store。只有当局部状态需要被多个组件使用时,再交给 `createStore`,用 Provider 决定共享范围,用 selector 选择组件真正需要的数据。
|
|
20
20
|
|
|
21
|
+
> [!TIP]
|
|
22
|
+
> **使用 Codex 安装**:复制下面这句话并粘贴给 Codex,它会同时安装依赖和当前项目的 Skill:
|
|
23
|
+
|
|
24
|
+
```text
|
|
25
|
+
使用当前项目的包管理器安装 @violetflux/kerros,然后运行 npx skills add violetflux/kerros --skill kerros --agent codex -y。
|
|
26
|
+
```
|
|
27
|
+
|
|
21
28
|
## 快速上手
|
|
22
29
|
|
|
23
30
|
### 创建 Store
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@violetflux/kerros",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Hook-native state sharing for React with focused selector subscriptions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
"store",
|
|
11
11
|
"selector",
|
|
12
12
|
"external-store",
|
|
13
|
-
"use-sync-external-store"
|
|
13
|
+
"use-sync-external-store",
|
|
14
|
+
"agent-skills",
|
|
15
|
+
"codex"
|
|
14
16
|
],
|
|
15
17
|
"homepage": "https://violetflux.github.io/kerros/",
|
|
16
18
|
"bugs": {
|
|
@@ -25,7 +27,8 @@
|
|
|
25
27
|
"type": "module",
|
|
26
28
|
"sideEffects": false,
|
|
27
29
|
"files": [
|
|
28
|
-
"dist"
|
|
30
|
+
"dist",
|
|
31
|
+
"skills"
|
|
29
32
|
],
|
|
30
33
|
"main": "./dist/index.cjs",
|
|
31
34
|
"module": "./dist/index.mjs",
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kerros
|
|
3
|
+
description: Implement, refactor, review, or test shared React state with @violetflux/kerros. Use for createStore, Provider scoping, selector subscriptions, cross-Store composition, migrating from Hox or frequently changing React Context, preventing Context-wide rerenders, and React 17–19 compatibility.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Kerros
|
|
7
|
+
|
|
8
|
+
Build shared state from ordinary React Hooks. Keep Provider scope and multiple instances while selectors prevent unrelated consumers from rerendering.
|
|
9
|
+
|
|
10
|
+
## Workflow
|
|
11
|
+
|
|
12
|
+
1. Inspect the project package manager, React version, existing state owner, Provider tree, and naming conventions.
|
|
13
|
+
2. Keep state local when only one component needs it. Create a Kerros Store only when several components need the same Hook state.
|
|
14
|
+
3. Group state by domain and identify one authoritative owner for every mutable value.
|
|
15
|
+
4. Create the Store, mount its Provider at the narrowest shared ancestor, and migrate consumers to focused selectors.
|
|
16
|
+
5. Order composed Providers from dependency to dependent and reject circular Store dependencies.
|
|
17
|
+
6. Run the project's typecheck, tests, lint, and the narrowest useful render test.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
Use the package manager already present in the project:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install @violetflux/kerros
|
|
25
|
+
pnpm add @violetflux/kerros
|
|
26
|
+
yarn add @violetflux/kerros
|
|
27
|
+
bun add @violetflux/kerros
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Kerros supports React 17, 18, and 19. Do not change package managers or create an additional lockfile.
|
|
31
|
+
|
|
32
|
+
## Core pattern
|
|
33
|
+
|
|
34
|
+
Write the Store as an ordinary Hook directly inside `createStore`. Name the public pair after the domain; do not repeat `Store` unless the codebase already requires it.
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { createStore } from '@violetflux/kerros'
|
|
38
|
+
import { useState } from 'react'
|
|
39
|
+
|
|
40
|
+
export const [useCounter, CounterProvider] = createStore(() => {
|
|
41
|
+
const [count, setCount] = useState(0)
|
|
42
|
+
const increment = () => setCount(v => v + 1)
|
|
43
|
+
|
|
44
|
+
return { count, increment }
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Mount the Provider at the narrowest ancestor shared by all consumers:
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
function App() {
|
|
52
|
+
return (
|
|
53
|
+
<CounterProvider>
|
|
54
|
+
<Counter />
|
|
55
|
+
</CounterProvider>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Select an object containing only the fields the component reads. Keep the selector inline and use `s` as its parameter:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
function Counter() {
|
|
64
|
+
const { count, increment } = useCounter(s => ({
|
|
65
|
+
count: s.count,
|
|
66
|
+
increment: s.increment,
|
|
67
|
+
}))
|
|
68
|
+
|
|
69
|
+
return <button onClick={increment}>{count}</button>
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Kerros shallowly compares the selected object's top-level fields with `Object.is`. An update to an unselected field must not rerender this component.
|
|
74
|
+
|
|
75
|
+
## Provider props
|
|
76
|
+
|
|
77
|
+
Accept initialization or scope-specific inputs as Store Hook props. Pass them to the generated Provider instead of reading mutable module globals.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
const [useGreeting, GreetingProvider] = createStore((props: { initialName: string }) => {
|
|
81
|
+
const [name, setName] = useState(props.initialName)
|
|
82
|
+
return { name, setName }
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
<GreetingProvider initialName="Ada">
|
|
86
|
+
<Profile />
|
|
87
|
+
</GreetingProvider>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Compose Stores
|
|
91
|
+
|
|
92
|
+
An inner Store may call an outer Store Hook. Mount the dependency first and keep the graph one-way.
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
const [useSession, SessionProvider] = createStore(() => {
|
|
96
|
+
const [userId, setUserId] = useState<string>()
|
|
97
|
+
return { userId, setUserId }
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
const [usePermissions, PermissionsProvider] = createStore(() => {
|
|
101
|
+
const { userId } = useSession(s => ({ userId: s.userId }))
|
|
102
|
+
return { canEdit: Boolean(userId) }
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
function Providers({ children }: PropsWithChildren) {
|
|
106
|
+
return (
|
|
107
|
+
<SessionProvider>
|
|
108
|
+
<PermissionsProvider>{children}</PermissionsProvider>
|
|
109
|
+
</SessionProvider>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Guardrails
|
|
115
|
+
|
|
116
|
+
- Require every Store read to use an object selector. Do not use array selectors.
|
|
117
|
+
- Select concrete fields and actions. Do not expose or select a changing aggregate Store snapshot.
|
|
118
|
+
- Do not wrap inline selectors with `useCallback`; Kerros handles selector identity.
|
|
119
|
+
- Keep public actions as ordinary functions. In React 19, use `useEffectEvent` only for events called from Effects, never as a public Store action.
|
|
120
|
+
- Do not mirror the same mutable state across Stores. Read it from its authoritative Store or move ownership.
|
|
121
|
+
- Do not create circular Store dependencies. Split ownership or invert the Provider order.
|
|
122
|
+
- Do not call a Store Hook outside its matching Provider; Kerros intentionally throws a clear error.
|
|
123
|
+
- Do not replace scoped Providers with a hidden module singleton. Put an application-wide Provider at the root only when the state is truly application-wide.
|
|
124
|
+
- Preserve SDK caches, subscriptions, and streams under a single owning Store when duplicating the Hook would duplicate external work.
|
|
125
|
+
- Respect the project's React version. Avoid React 19-only APIs when the consuming project still supports React 17 or 18.
|
|
126
|
+
|
|
127
|
+
## Migrate existing state
|
|
128
|
+
|
|
129
|
+
- From React Context: keep the Provider boundary, move the changing value into `createStore`, and replace broad `useContext` reads with focused selectors.
|
|
130
|
+
- From Hox: replace the factory with `createStore`, add the explicit Provider, remove compatibility exports, and migrate every consumer to an object selector.
|
|
131
|
+
- From a global Store: split by domain only when ownership and dependencies stay clear; do not split merely by field count.
|
|
132
|
+
|
|
133
|
+
## Verify
|
|
134
|
+
|
|
135
|
+
- Confirm all consumers are below the correct Provider and multiple Provider instances stay isolated.
|
|
136
|
+
- Test Provider props, Strict Mode, subscription cleanup, and the outside-Provider error when changing Store infrastructure.
|
|
137
|
+
- Add a render-count test showing that changing an unselected field does not rerender the consumer.
|
|
138
|
+
- Search for broad Store selections, array selectors, duplicate subscriptions, and dependency cycles.
|
|
139
|
+
- Run the consuming project's existing validation commands without introducing a new package manager.
|