@esmx/class-state 3.0.0-rc.24 → 3.0.0-rc.26
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/dist/connect.mjs +37 -34
- package/dist/connect.test.mjs +66 -34
- package/dist/create.mjs +7 -3
- package/dist/vue.test.mjs +12 -3
- package/package.json +8 -8
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,19 +190,23 @@ 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
|
}
|
|
@@ -204,10 +222,10 @@ test("Params", () => {
|
|
|
204
222
|
const state = createState();
|
|
205
223
|
const connectStore = connectState(state);
|
|
206
224
|
class User {
|
|
207
|
-
name = "";
|
|
208
|
-
uid;
|
|
209
225
|
constructor(uid) {
|
|
210
|
-
this
|
|
226
|
+
__publicField(this, "name", "");
|
|
227
|
+
__publicField(this, "uid");
|
|
228
|
+
this.uid = uid != null ? uid : "";
|
|
211
229
|
}
|
|
212
230
|
$setName(name) {
|
|
213
231
|
this.name = name;
|
|
@@ -229,9 +247,11 @@ test("Call commit multiple times", () => {
|
|
|
229
247
|
const state = createState();
|
|
230
248
|
const connectStore = connectState(state);
|
|
231
249
|
class User {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
250
|
+
constructor() {
|
|
251
|
+
__publicField(this, "name", "");
|
|
252
|
+
__publicField(this, "age", 0);
|
|
253
|
+
__publicField(this, "text", "");
|
|
254
|
+
}
|
|
235
255
|
$setName(name) {
|
|
236
256
|
this.name = name;
|
|
237
257
|
return "1";
|
|
@@ -256,7 +276,9 @@ test("No a submit function modification state", () => {
|
|
|
256
276
|
const state = createState();
|
|
257
277
|
const connectStore = connectState(state);
|
|
258
278
|
class User {
|
|
259
|
-
|
|
279
|
+
constructor() {
|
|
280
|
+
__publicField(this, "name", "");
|
|
281
|
+
}
|
|
260
282
|
setName(name) {
|
|
261
283
|
this.name = name;
|
|
262
284
|
}
|
|
@@ -270,7 +292,9 @@ test("Equal submit function", () => {
|
|
|
270
292
|
const state = createState();
|
|
271
293
|
const connectStore = connectState(state);
|
|
272
294
|
class User {
|
|
273
|
-
|
|
295
|
+
constructor() {
|
|
296
|
+
__publicField(this, "name", "");
|
|
297
|
+
}
|
|
274
298
|
$setName(name) {
|
|
275
299
|
this.name = name;
|
|
276
300
|
}
|
|
@@ -288,7 +312,9 @@ test("State Restore", () => {
|
|
|
288
312
|
});
|
|
289
313
|
const connectStore = connectState(state);
|
|
290
314
|
class User {
|
|
291
|
-
|
|
315
|
+
constructor() {
|
|
316
|
+
__publicField(this, "name", "");
|
|
317
|
+
}
|
|
292
318
|
$setName(name) {
|
|
293
319
|
this.name = name;
|
|
294
320
|
}
|
|
@@ -300,8 +326,10 @@ test("update value", () => {
|
|
|
300
326
|
const state = createState();
|
|
301
327
|
const connectStore = connectState(state);
|
|
302
328
|
class Count {
|
|
303
|
-
|
|
304
|
-
|
|
329
|
+
constructor() {
|
|
330
|
+
__publicField(this, "value", 0);
|
|
331
|
+
__publicField(this, "text", "");
|
|
332
|
+
}
|
|
305
333
|
$inc() {
|
|
306
334
|
this.value++;
|
|
307
335
|
}
|
|
@@ -334,7 +362,9 @@ test("default connecting", () => {
|
|
|
334
362
|
});
|
|
335
363
|
const connectStore = connectState(state);
|
|
336
364
|
class Count {
|
|
337
|
-
|
|
365
|
+
constructor() {
|
|
366
|
+
__publicField(this, "value", 0);
|
|
367
|
+
}
|
|
338
368
|
$inc() {
|
|
339
369
|
this.value++;
|
|
340
370
|
}
|
|
@@ -353,7 +383,9 @@ test("update state", () => {
|
|
|
353
383
|
});
|
|
354
384
|
const connectStore = connectState(state);
|
|
355
385
|
class Count {
|
|
356
|
-
|
|
386
|
+
constructor() {
|
|
387
|
+
__publicField(this, "value", 0);
|
|
388
|
+
}
|
|
357
389
|
$inc() {
|
|
358
390
|
this.value++;
|
|
359
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/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
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@biomejs/biome": "1.9.4",
|
|
36
|
-
"@esmx/lint": "3.0.0-rc.
|
|
37
|
-
"@types/node": "
|
|
38
|
-
"@vitest/coverage-v8": "3.
|
|
36
|
+
"@esmx/lint": "3.0.0-rc.26",
|
|
37
|
+
"@types/node": "^24.0.10",
|
|
38
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
39
39
|
"@vue/compiler-dom": "^3.5.13",
|
|
40
|
-
"stylelint": "16.
|
|
41
|
-
"typescript": "5.8.
|
|
40
|
+
"stylelint": "16.21.0",
|
|
41
|
+
"typescript": "5.8.3",
|
|
42
42
|
"unbuild": "3.5.0",
|
|
43
|
-
"vitest": "3.
|
|
43
|
+
"vitest": "3.2.4",
|
|
44
44
|
"vue": "^3.5.13"
|
|
45
45
|
},
|
|
46
|
-
"version": "3.0.0-rc.
|
|
46
|
+
"version": "3.0.0-rc.26",
|
|
47
47
|
"type": "module",
|
|
48
48
|
"private": false,
|
|
49
49
|
"exports": {
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"template",
|
|
63
63
|
"public"
|
|
64
64
|
],
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "2f52f94c8ac27aca32ef3148afd109d0f0470d52"
|
|
66
66
|
}
|