@esmx/class-state 3.0.0-rc.11 → 3.0.0-rc.110
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/LICENSE +1 -1
- package/README.md +58 -0
- package/README.zh-CN.md +58 -0
- package/dist/connect.mjs +37 -34
- package/dist/connect.test.mjs +67 -34
- package/dist/create.mjs +7 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/vue.test.mjs +12 -3
- package/package.json +11 -13
- package/src/connect.test.ts +2 -0
- package/src/connect.ts +1 -1
- package/src/index.ts +4 -4
package/LICENSE
CHANGED
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://esmx.dev/logo.svg?t=2025" width="120" alt="Esmx Logo" />
|
|
3
|
+
<h1>@esmx/class-state</h1>
|
|
4
|
+
|
|
5
|
+
<div>
|
|
6
|
+
<a href="https://www.npmjs.com/package/@esmx/class-state">
|
|
7
|
+
<img src="https://img.shields.io/npm/v/@esmx/class-state.svg" alt="npm version" />
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://github.com/esmnext/esmx/actions/workflows/build.yml">
|
|
10
|
+
<img src="https://github.com/esmnext/esmx/actions/workflows/build.yml/badge.svg" alt="Build" />
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://esmx.dev/coverage/">
|
|
13
|
+
<img src="https://img.shields.io/badge/coverage-live%20report-brightgreen" alt="Coverage Report" />
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://nodejs.org/">
|
|
16
|
+
<img src="https://img.shields.io/node/v/@esmx/class-state.svg" alt="node version" />
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://bundlephobia.com/package/@esmx/class-state">
|
|
19
|
+
<img src="https://img.shields.io/bundlephobia/minzip/@esmx/class-state" alt="size" />
|
|
20
|
+
</a>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<p>Lightweight class-based state management solution for modern JavaScript applications</p>
|
|
24
|
+
|
|
25
|
+
<p>
|
|
26
|
+
English | <a href="https://github.com/esmnext/esmx/blob/master/packages/class-state/README.zh-CN.md">中文</a>
|
|
27
|
+
</p>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## 🚀 Features
|
|
31
|
+
|
|
32
|
+
- **Class-Based Design** - Clean and intuitive class-based state management
|
|
33
|
+
- **Framework Agnostic** - Works with any JavaScript framework or vanilla JS
|
|
34
|
+
- **TypeScript Ready** - Full TypeScript support with excellent type inference
|
|
35
|
+
- **Reactive System** - Built-in reactivity for automatic UI updates
|
|
36
|
+
- **Lightweight** - Minimal bundle size with maximum functionality
|
|
37
|
+
- **Modern API** - Uses modern JavaScript features and patterns
|
|
38
|
+
|
|
39
|
+
## 📦 Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# npm
|
|
43
|
+
npm install @esmx/class-state
|
|
44
|
+
|
|
45
|
+
# pnpm
|
|
46
|
+
pnpm add @esmx/class-state
|
|
47
|
+
|
|
48
|
+
# yarn
|
|
49
|
+
yarn add @esmx/class-state
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 📚 Documentation
|
|
53
|
+
|
|
54
|
+
Visit the [official documentation](https://esmx.dev) for detailed usage guides and API reference.
|
|
55
|
+
|
|
56
|
+
## 📄 License
|
|
57
|
+
|
|
58
|
+
MIT © [Esmx Team](https://github.com/esmnext/esmx)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://esmx.dev/logo.svg?t=2025" width="120" alt="Esmx Logo" />
|
|
3
|
+
<h1>@esmx/class-state</h1>
|
|
4
|
+
|
|
5
|
+
<div>
|
|
6
|
+
<a href="https://www.npmjs.com/package/@esmx/class-state">
|
|
7
|
+
<img src="https://img.shields.io/npm/v/@esmx/class-state.svg" alt="npm version" />
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://github.com/esmnext/esmx/actions/workflows/build.yml">
|
|
10
|
+
<img src="https://github.com/esmnext/esmx/actions/workflows/build.yml/badge.svg" alt="Build" />
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://esmx.dev/coverage/">
|
|
13
|
+
<img src="https://img.shields.io/badge/coverage-live%20report-brightgreen" alt="Coverage Report" />
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://nodejs.org/">
|
|
16
|
+
<img src="https://img.shields.io/node/v/@esmx/class-state.svg" alt="node version" />
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://bundlephobia.com/package/@esmx/class-state">
|
|
19
|
+
<img src="https://img.shields.io/bundlephobia/minzip/@esmx/class-state" alt="size" />
|
|
20
|
+
</a>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<p>为现代 JavaScript 应用提供的轻量级基于类的状态管理解决方案</p>
|
|
24
|
+
|
|
25
|
+
<p>
|
|
26
|
+
<a href="https://github.com/esmnext/esmx/blob/master/packages/class-state/README.md">English</a> | 中文
|
|
27
|
+
</p>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## 🚀 特性
|
|
31
|
+
|
|
32
|
+
- **基于类的设计** - 简洁直观的基于类的状态管理
|
|
33
|
+
- **框架无关** - 适用于任何 JavaScript 框架或原生 JS
|
|
34
|
+
- **TypeScript 就绪** - 完整的 TypeScript 支持,出色的类型推断
|
|
35
|
+
- **响应式系统** - 内置响应性,自动更新 UI
|
|
36
|
+
- **轻量级** - 最小化包体积,最大化功能
|
|
37
|
+
- **现代 API** - 使用现代 JavaScript 特性和模式
|
|
38
|
+
|
|
39
|
+
## 📦 安装
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# npm
|
|
43
|
+
npm install @esmx/class-state
|
|
44
|
+
|
|
45
|
+
# pnpm
|
|
46
|
+
pnpm add @esmx/class-state
|
|
47
|
+
|
|
48
|
+
# yarn
|
|
49
|
+
yarn add @esmx/class-state
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 📚 文档
|
|
53
|
+
|
|
54
|
+
访问[官方文档](https://esmx.dev)获取详细的使用指南和 API 参考。
|
|
55
|
+
|
|
56
|
+
## 📄 许可证
|
|
57
|
+
|
|
58
|
+
MIT © [Esmx Team](https://github.com/esmnext/esmx)
|
package/dist/connect.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1
4
|
import { produce } from "immer";
|
|
2
5
|
import { getStateContext } from "./create.mjs";
|
|
3
6
|
let currentStateContext = null;
|
|
@@ -7,40 +10,40 @@ let sid = 0;
|
|
|
7
10
|
function noon() {
|
|
8
11
|
}
|
|
9
12
|
export class StoreContext {
|
|
10
|
-
/**
|
|
11
|
-
* 全局的状态上下文
|
|
12
|
-
*/
|
|
13
|
-
_stateContext;
|
|
14
|
-
/**
|
|
15
|
-
* 原始实例
|
|
16
|
-
*/
|
|
17
|
-
_raw;
|
|
18
|
-
/**
|
|
19
|
-
* 原始实例的代理,每次状态变化时,代理都会更新
|
|
20
|
-
*/
|
|
21
|
-
_proxy;
|
|
22
|
-
/**
|
|
23
|
-
* 当前的 state 是否是草稿状态
|
|
24
|
-
*/
|
|
25
|
-
_drafting = false;
|
|
26
|
-
/**
|
|
27
|
-
* $ 函数的缓存对象
|
|
28
|
-
*/
|
|
29
|
-
_cacheCommit = /* @__PURE__ */ new Map();
|
|
30
|
-
/**
|
|
31
|
-
* 当前的 store 的存储路径
|
|
32
|
-
*/
|
|
33
|
-
keyPath;
|
|
34
|
-
/**
|
|
35
|
-
* 最新的状态
|
|
36
|
-
*/
|
|
37
|
-
state;
|
|
38
|
-
/**
|
|
39
|
-
* 当前的 store 的 state 是否已经连接到全局的 state 中
|
|
40
|
-
*/
|
|
41
|
-
connecting;
|
|
42
|
-
_subs = [];
|
|
43
13
|
constructor(stateContext, raw, state, keyPath) {
|
|
14
|
+
/**
|
|
15
|
+
* 全局的状态上下文
|
|
16
|
+
*/
|
|
17
|
+
__publicField(this, "_stateContext");
|
|
18
|
+
/**
|
|
19
|
+
* 原始实例
|
|
20
|
+
*/
|
|
21
|
+
__publicField(this, "_raw");
|
|
22
|
+
/**
|
|
23
|
+
* 原始实例的代理,每次状态变化时,代理都会更新
|
|
24
|
+
*/
|
|
25
|
+
__publicField(this, "_proxy");
|
|
26
|
+
/**
|
|
27
|
+
* 当前的 state 是否是草稿状态
|
|
28
|
+
*/
|
|
29
|
+
__publicField(this, "_drafting", false);
|
|
30
|
+
/**
|
|
31
|
+
* $ 函数的缓存对象
|
|
32
|
+
*/
|
|
33
|
+
__publicField(this, "_cacheCommit", /* @__PURE__ */ new Map());
|
|
34
|
+
/**
|
|
35
|
+
* 当前的 store 的存储路径
|
|
36
|
+
*/
|
|
37
|
+
__publicField(this, "keyPath");
|
|
38
|
+
/**
|
|
39
|
+
* 最新的状态
|
|
40
|
+
*/
|
|
41
|
+
__publicField(this, "state");
|
|
42
|
+
/**
|
|
43
|
+
* 当前的 store 的 state 是否已经连接到全局的 state 中
|
|
44
|
+
*/
|
|
45
|
+
__publicField(this, "connecting");
|
|
46
|
+
__publicField(this, "_subs", []);
|
|
44
47
|
this._stateContext = stateContext;
|
|
45
48
|
stateContext.add(keyPath, this);
|
|
46
49
|
this._raw = raw;
|
|
@@ -156,7 +159,7 @@ export class StoreContext {
|
|
|
156
159
|
return true;
|
|
157
160
|
}
|
|
158
161
|
throw new Error(
|
|
159
|
-
|
|
162
|
+
"Change the state in the agreed commit function, For example, $".concat(p, "('").concat(String(newValue), "')")
|
|
160
163
|
);
|
|
161
164
|
}
|
|
162
165
|
return Reflect.set(target, p, newValue, receiver);
|
package/dist/connect.test.mjs
CHANGED
|
@@ -9,11 +9,11 @@ test("Base", () => {
|
|
|
9
9
|
const STORE_NAME = "user";
|
|
10
10
|
const connectStore = connectState(state);
|
|
11
11
|
class User {
|
|
12
|
-
name = "";
|
|
13
|
-
age = 18;
|
|
14
|
-
text = "";
|
|
15
|
-
online = false;
|
|
16
12
|
constructor() {
|
|
13
|
+
__publicField(this, "name", "");
|
|
14
|
+
__publicField(this, "age", 18);
|
|
15
|
+
__publicField(this, "text", "");
|
|
16
|
+
__publicField(this, "online", false);
|
|
17
17
|
Object.defineProperty(this, "online", {
|
|
18
18
|
enumerable: false
|
|
19
19
|
});
|
|
@@ -25,7 +25,7 @@ test("Base", () => {
|
|
|
25
25
|
this.age = age;
|
|
26
26
|
}
|
|
27
27
|
$buildText() {
|
|
28
|
-
this.text =
|
|
28
|
+
this.text = "".concat(this.name, " is ").concat(this.age, " years old.");
|
|
29
29
|
}
|
|
30
30
|
$toggleOnline() {
|
|
31
31
|
this.online = !this.online;
|
|
@@ -40,12 +40,14 @@ test("Object type", () => {
|
|
|
40
40
|
const STORE_NAME = "user";
|
|
41
41
|
const connectStore = connectState(state);
|
|
42
42
|
class User {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
constructor() {
|
|
44
|
+
__publicField(this, "data", {
|
|
45
|
+
name: "",
|
|
46
|
+
age: 18
|
|
47
|
+
});
|
|
48
|
+
}
|
|
47
49
|
get text() {
|
|
48
|
-
return
|
|
50
|
+
return "".concat(this.data.name, " is ").concat(this.data.age, " years old.");
|
|
49
51
|
}
|
|
50
52
|
$setName(name) {
|
|
51
53
|
this.data.name = name;
|
|
@@ -67,7 +69,9 @@ test("Commit function this bind", () => {
|
|
|
67
69
|
const STORE_NAME = "user";
|
|
68
70
|
const connectStore = connectState(state);
|
|
69
71
|
class User {
|
|
70
|
-
|
|
72
|
+
constructor() {
|
|
73
|
+
__publicField(this, "name", "");
|
|
74
|
+
}
|
|
71
75
|
$setName(name) {
|
|
72
76
|
this.name = name;
|
|
73
77
|
}
|
|
@@ -82,7 +86,9 @@ test("Commit function return value and args", () => {
|
|
|
82
86
|
const STORE_NAME = "user";
|
|
83
87
|
const connectStore = connectState(state);
|
|
84
88
|
class User {
|
|
85
|
-
|
|
89
|
+
constructor() {
|
|
90
|
+
__publicField(this, "list", []);
|
|
91
|
+
}
|
|
86
92
|
$add(...list) {
|
|
87
93
|
this.list.push(...list);
|
|
88
94
|
return true;
|
|
@@ -97,7 +103,9 @@ test("Instance reference", () => {
|
|
|
97
103
|
const STORE_NAME = "user";
|
|
98
104
|
const connectStore = connectState(state);
|
|
99
105
|
class User {
|
|
100
|
-
|
|
106
|
+
constructor() {
|
|
107
|
+
__publicField(this, "name", "");
|
|
108
|
+
}
|
|
101
109
|
$setName(name) {
|
|
102
110
|
this.name = name;
|
|
103
111
|
}
|
|
@@ -112,7 +120,9 @@ test("Disconnect", () => {
|
|
|
112
120
|
const STORE_NAME = "user";
|
|
113
121
|
const connectStore = connectState(state);
|
|
114
122
|
class User {
|
|
115
|
-
|
|
123
|
+
constructor() {
|
|
124
|
+
__publicField(this, "name", "");
|
|
125
|
+
}
|
|
116
126
|
$setName(name) {
|
|
117
127
|
this.name = name;
|
|
118
128
|
}
|
|
@@ -136,8 +146,10 @@ test("Preset state", () => {
|
|
|
136
146
|
});
|
|
137
147
|
const connectStore = connectState(state);
|
|
138
148
|
class User {
|
|
139
|
-
|
|
140
|
-
|
|
149
|
+
constructor() {
|
|
150
|
+
__publicField(this, "name", "");
|
|
151
|
+
__publicField(this, "age", 18);
|
|
152
|
+
}
|
|
141
153
|
}
|
|
142
154
|
const user = connectStore(User, STORE_NAME);
|
|
143
155
|
assert.strictEqual(user.name, "jack");
|
|
@@ -150,8 +162,10 @@ test("State modification delay", () => {
|
|
|
150
162
|
const state = createState();
|
|
151
163
|
const connectStore = connectState(state);
|
|
152
164
|
class User {
|
|
153
|
-
|
|
154
|
-
|
|
165
|
+
constructor() {
|
|
166
|
+
__publicField(this, "name", "");
|
|
167
|
+
__publicField(this, "age", 0);
|
|
168
|
+
}
|
|
155
169
|
$setAge(age) {
|
|
156
170
|
this.age = age;
|
|
157
171
|
}
|
|
@@ -176,24 +190,29 @@ test("Multiple instances", () => {
|
|
|
176
190
|
const state = createState();
|
|
177
191
|
const _connectStore = connectState(state);
|
|
178
192
|
class User {
|
|
179
|
-
|
|
193
|
+
constructor() {
|
|
194
|
+
__publicField(this, "name", "");
|
|
195
|
+
}
|
|
180
196
|
get blog() {
|
|
181
197
|
return foreignStore(Blog, "blog");
|
|
182
198
|
}
|
|
183
199
|
get log() {
|
|
184
|
-
return
|
|
200
|
+
return "'".concat(this.name, "' published '").concat(this.blog.text, "'");
|
|
185
201
|
}
|
|
186
202
|
$setName(name) {
|
|
187
203
|
this.name = name;
|
|
188
204
|
}
|
|
189
205
|
}
|
|
190
206
|
class Blog {
|
|
191
|
-
|
|
207
|
+
constructor() {
|
|
208
|
+
__publicField(this, "text", "");
|
|
209
|
+
}
|
|
192
210
|
$setText(text) {
|
|
193
211
|
this.text = text;
|
|
194
212
|
}
|
|
195
213
|
}
|
|
196
214
|
const user = _connectStore(User, "user");
|
|
215
|
+
const blog = _connectStore(Blog, "blog");
|
|
197
216
|
user.$setName("jack");
|
|
198
217
|
user.blog.$setText("hello world.");
|
|
199
218
|
assert.strictEqual(user.name, "jack");
|
|
@@ -203,10 +222,10 @@ test("Params", () => {
|
|
|
203
222
|
const state = createState();
|
|
204
223
|
const connectStore = connectState(state);
|
|
205
224
|
class User {
|
|
206
|
-
name = "";
|
|
207
|
-
uid;
|
|
208
225
|
constructor(uid) {
|
|
209
|
-
this
|
|
226
|
+
__publicField(this, "name", "");
|
|
227
|
+
__publicField(this, "uid");
|
|
228
|
+
this.uid = uid != null ? uid : "";
|
|
210
229
|
}
|
|
211
230
|
$setName(name) {
|
|
212
231
|
this.name = name;
|
|
@@ -228,9 +247,11 @@ test("Call commit multiple times", () => {
|
|
|
228
247
|
const state = createState();
|
|
229
248
|
const connectStore = connectState(state);
|
|
230
249
|
class User {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
250
|
+
constructor() {
|
|
251
|
+
__publicField(this, "name", "");
|
|
252
|
+
__publicField(this, "age", 0);
|
|
253
|
+
__publicField(this, "text", "");
|
|
254
|
+
}
|
|
234
255
|
$setName(name) {
|
|
235
256
|
this.name = name;
|
|
236
257
|
return "1";
|
|
@@ -255,7 +276,9 @@ test("No a submit function modification state", () => {
|
|
|
255
276
|
const state = createState();
|
|
256
277
|
const connectStore = connectState(state);
|
|
257
278
|
class User {
|
|
258
|
-
|
|
279
|
+
constructor() {
|
|
280
|
+
__publicField(this, "name", "");
|
|
281
|
+
}
|
|
259
282
|
setName(name) {
|
|
260
283
|
this.name = name;
|
|
261
284
|
}
|
|
@@ -269,7 +292,9 @@ test("Equal submit function", () => {
|
|
|
269
292
|
const state = createState();
|
|
270
293
|
const connectStore = connectState(state);
|
|
271
294
|
class User {
|
|
272
|
-
|
|
295
|
+
constructor() {
|
|
296
|
+
__publicField(this, "name", "");
|
|
297
|
+
}
|
|
273
298
|
$setName(name) {
|
|
274
299
|
this.name = name;
|
|
275
300
|
}
|
|
@@ -287,7 +312,9 @@ test("State Restore", () => {
|
|
|
287
312
|
});
|
|
288
313
|
const connectStore = connectState(state);
|
|
289
314
|
class User {
|
|
290
|
-
|
|
315
|
+
constructor() {
|
|
316
|
+
__publicField(this, "name", "");
|
|
317
|
+
}
|
|
291
318
|
$setName(name) {
|
|
292
319
|
this.name = name;
|
|
293
320
|
}
|
|
@@ -299,8 +326,10 @@ test("update value", () => {
|
|
|
299
326
|
const state = createState();
|
|
300
327
|
const connectStore = connectState(state);
|
|
301
328
|
class Count {
|
|
302
|
-
|
|
303
|
-
|
|
329
|
+
constructor() {
|
|
330
|
+
__publicField(this, "value", 0);
|
|
331
|
+
__publicField(this, "text", "");
|
|
332
|
+
}
|
|
304
333
|
$inc() {
|
|
305
334
|
this.value++;
|
|
306
335
|
}
|
|
@@ -333,7 +362,9 @@ test("default connecting", () => {
|
|
|
333
362
|
});
|
|
334
363
|
const connectStore = connectState(state);
|
|
335
364
|
class Count {
|
|
336
|
-
|
|
365
|
+
constructor() {
|
|
366
|
+
__publicField(this, "value", 0);
|
|
367
|
+
}
|
|
337
368
|
$inc() {
|
|
338
369
|
this.value++;
|
|
339
370
|
}
|
|
@@ -352,7 +383,9 @@ test("update state", () => {
|
|
|
352
383
|
});
|
|
353
384
|
const connectStore = connectState(state);
|
|
354
385
|
class Count {
|
|
355
|
-
|
|
386
|
+
constructor() {
|
|
387
|
+
__publicField(this, "value", 0);
|
|
388
|
+
}
|
|
356
389
|
$inc() {
|
|
357
390
|
this.value++;
|
|
358
391
|
}
|
package/dist/create.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1
4
|
const rootMap = /* @__PURE__ */ new WeakMap();
|
|
2
5
|
export class StateContext {
|
|
3
|
-
state;
|
|
4
|
-
storeContext = /* @__PURE__ */ new Map();
|
|
5
6
|
constructor(state) {
|
|
7
|
+
__publicField(this, "state");
|
|
8
|
+
__publicField(this, "storeContext", /* @__PURE__ */ new Map());
|
|
6
9
|
this.state = state;
|
|
7
10
|
}
|
|
8
11
|
depend(fullPath) {
|
|
@@ -15,7 +18,8 @@ export class StateContext {
|
|
|
15
18
|
return name in this.state.value;
|
|
16
19
|
}
|
|
17
20
|
get(name) {
|
|
18
|
-
|
|
21
|
+
var _a;
|
|
22
|
+
return (_a = this.storeContext.get(name)) != null ? _a : null;
|
|
19
23
|
}
|
|
20
24
|
add(name, storeContext) {
|
|
21
25
|
this.storeContext.set(name, storeContext);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
+
export { connectState, foreignStore, LIFE_CYCLE_CREATED, LIFE_CYCLE_DISPOSE, type StoreConstructor, type StoreContext, type StoreInstance, type StoreParams } from './connect';
|
|
1
2
|
export { createState, type State } from './create';
|
|
2
|
-
export { connectState, foreignStore, type StoreConstructor, type StoreContext, type StoreInstance, type StoreParams, LIFE_CYCLE_CREATED, LIFE_CYCLE_DISPOSE } from './connect';
|
package/dist/index.mjs
CHANGED
package/dist/vue.test.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1
4
|
import { assert, test } from "vitest";
|
|
2
5
|
import { nextTick, reactive, watch } from "vue";
|
|
3
6
|
import { connectState } from "./connect.mjs";
|
|
@@ -6,7 +9,9 @@ test("base", async () => {
|
|
|
6
9
|
const state = createState(reactive({ value: {} }));
|
|
7
10
|
const connectStore = connectState(state);
|
|
8
11
|
class User {
|
|
9
|
-
|
|
12
|
+
constructor() {
|
|
13
|
+
__publicField(this, "name", "");
|
|
14
|
+
}
|
|
10
15
|
$setName(name) {
|
|
11
16
|
this.name = name;
|
|
12
17
|
}
|
|
@@ -32,7 +37,9 @@ test("base2", async () => {
|
|
|
32
37
|
const state = createState(reactive({ value: {} }));
|
|
33
38
|
const connectStore = connectState(state);
|
|
34
39
|
class User {
|
|
35
|
-
|
|
40
|
+
constructor() {
|
|
41
|
+
__publicField(this, "name", "");
|
|
42
|
+
}
|
|
36
43
|
$setName(name) {
|
|
37
44
|
this.name = name;
|
|
38
45
|
}
|
|
@@ -56,7 +63,9 @@ test("watch root", async () => {
|
|
|
56
63
|
const state = createState(reactive({ value: {} }));
|
|
57
64
|
const connectStore = connectState(state);
|
|
58
65
|
class User {
|
|
59
|
-
|
|
66
|
+
constructor() {
|
|
67
|
+
__publicField(this, "name", "");
|
|
68
|
+
}
|
|
60
69
|
$setName(name) {
|
|
61
70
|
this.name = name;
|
|
62
71
|
}
|
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"lint:js": "biome check --write --no-errors-on-unmatched",
|
|
25
|
-
"lint:css": "
|
|
25
|
+
"lint:css": "pnpm run lint:js",
|
|
26
26
|
"lint:type": "tsc --noEmit",
|
|
27
27
|
"test": "vitest run --pass-with-no-tests",
|
|
28
28
|
"coverage": "vitest run --coverage --pass-with-no-tests",
|
|
@@ -32,18 +32,16 @@
|
|
|
32
32
|
"immer": "^10.1.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@biomejs/biome": "
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"vitest": "3.0.8",
|
|
44
|
-
"vue": "^3.5.13"
|
|
35
|
+
"@biomejs/biome": "2.3.7",
|
|
36
|
+
"@types/node": "^24.0.0",
|
|
37
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
38
|
+
"@vue/compiler-dom": "^3.5.23",
|
|
39
|
+
"typescript": "5.9.3",
|
|
40
|
+
"unbuild": "3.6.1",
|
|
41
|
+
"vitest": "3.2.4",
|
|
42
|
+
"vue": "^3.5.23"
|
|
45
43
|
},
|
|
46
|
-
"version": "3.0.0-rc.
|
|
44
|
+
"version": "3.0.0-rc.110",
|
|
47
45
|
"type": "module",
|
|
48
46
|
"private": false,
|
|
49
47
|
"exports": {
|
|
@@ -62,5 +60,5 @@
|
|
|
62
60
|
"template",
|
|
63
61
|
"public"
|
|
64
62
|
],
|
|
65
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "0cea5581bcb0774a0350565bcda33073c3123a3d"
|
|
66
64
|
}
|
package/src/connect.test.ts
CHANGED
|
@@ -250,6 +250,8 @@ test('Multiple instances', () => {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
const user = _connectStore(User, 'user');
|
|
253
|
+
// Create blog instance first before accessing it from user
|
|
254
|
+
const blog = _connectStore(Blog, 'blog');
|
|
253
255
|
|
|
254
256
|
user.$setName('jack');
|
|
255
257
|
user.blog.$setText('hello world.');
|
package/src/connect.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
2
2
|
import { produce } from 'immer';
|
|
3
3
|
|
|
4
|
-
import { type State, type StateContext
|
|
4
|
+
import { getStateContext, type State, type StateContext } from './create';
|
|
5
5
|
export type StoreParams = Record<string, any>;
|
|
6
6
|
export type StoreConstructor = new (cacheKey?: string) => any;
|
|
7
7
|
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { createState, type State } from './create';
|
|
2
1
|
export {
|
|
3
2
|
connectState,
|
|
4
3
|
foreignStore,
|
|
4
|
+
LIFE_CYCLE_CREATED,
|
|
5
|
+
LIFE_CYCLE_DISPOSE,
|
|
5
6
|
type StoreConstructor,
|
|
6
7
|
type StoreContext,
|
|
7
8
|
type StoreInstance,
|
|
8
|
-
type StoreParams
|
|
9
|
-
LIFE_CYCLE_CREATED,
|
|
10
|
-
LIFE_CYCLE_DISPOSE
|
|
9
|
+
type StoreParams
|
|
11
10
|
} from './connect';
|
|
11
|
+
export { createState, type State } from './create';
|