wevu 0.0.1 → 1.0.0-alpha.1
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.md +119 -0
- package/dist/index-0dF4y5p6.d.mts +80 -0
- package/dist/index-DVEFI-Uo.d.cts +80 -0
- package/dist/index.cjs +525 -154
- package/dist/index.d.cts +397 -54
- package/dist/index.d.mts +397 -54
- package/dist/index.mjs +465 -119
- package/dist/store-BcU7YVhB.mjs +638 -0
- package/dist/store-Cmw9vWBT.cjs +764 -0
- package/dist/store.cjs +4 -246
- package/dist/store.d.cts +2 -69
- package/dist/store.d.mts +2 -69
- package/dist/store.mjs +1 -243
- package/package.json +24 -16
- package/dist/ref-0isFdYQ8.d.cts +0 -9
- package/dist/ref-BHYwO374.d.mts +0 -9
- package/dist/ref-DS-k2oUF.mjs +0 -271
- package/dist/ref-DtCdcykK.cjs +0 -349
package/dist/store.cjs
CHANGED
|
@@ -1,247 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_store = require('./store-Cmw9vWBT.cjs');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const afterCbs = [];
|
|
7
|
-
const errorCbs = [];
|
|
8
|
-
const after = (cb) => afterCbs.push(cb);
|
|
9
|
-
const onError = (cb) => errorCbs.push(cb);
|
|
10
|
-
actionSubs.forEach((sub) => {
|
|
11
|
-
try {
|
|
12
|
-
sub({
|
|
13
|
-
name,
|
|
14
|
-
store,
|
|
15
|
-
args,
|
|
16
|
-
after,
|
|
17
|
-
onError
|
|
18
|
-
});
|
|
19
|
-
} catch {}
|
|
20
|
-
});
|
|
21
|
-
let res;
|
|
22
|
-
try {
|
|
23
|
-
res = action.apply(store, args);
|
|
24
|
-
} catch (e) {
|
|
25
|
-
errorCbs.forEach((cb) => cb(e));
|
|
26
|
-
throw e;
|
|
27
|
-
}
|
|
28
|
-
const finalize = (r) => {
|
|
29
|
-
afterCbs.forEach((cb) => cb(r));
|
|
30
|
-
return r;
|
|
31
|
-
};
|
|
32
|
-
if (res && typeof res.then === "function") return res.then((r) => finalize(r), (e) => {
|
|
33
|
-
errorCbs.forEach((cb) => cb(e));
|
|
34
|
-
return Promise.reject(e);
|
|
35
|
-
});
|
|
36
|
-
return finalize(res);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/store/utils.ts
|
|
42
|
-
function isObject(val) {
|
|
43
|
-
return typeof val === "object" && val !== null;
|
|
44
|
-
}
|
|
45
|
-
function mergeShallow(target, patch) {
|
|
46
|
-
for (const k in patch) target[k] = patch[k];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region src/store/base.ts
|
|
51
|
-
function createBaseApi(id, stateObj, notify, resetImpl) {
|
|
52
|
-
const api = { $id: id };
|
|
53
|
-
Object.defineProperty(api, "$state", {
|
|
54
|
-
get() {
|
|
55
|
-
return stateObj;
|
|
56
|
-
},
|
|
57
|
-
set(v) {
|
|
58
|
-
if (stateObj && isObject(v)) {
|
|
59
|
-
mergeShallow(stateObj, v);
|
|
60
|
-
notify("patch object");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
api.$patch = (patch) => {
|
|
65
|
-
if (!stateObj) {
|
|
66
|
-
if (typeof patch === "function") {
|
|
67
|
-
patch(api);
|
|
68
|
-
notify("patch function");
|
|
69
|
-
} else {
|
|
70
|
-
mergeShallow(api, patch);
|
|
71
|
-
notify("patch object");
|
|
72
|
-
}
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (typeof patch === "function") {
|
|
76
|
-
patch(stateObj);
|
|
77
|
-
notify("patch function");
|
|
78
|
-
} else {
|
|
79
|
-
mergeShallow(stateObj, patch);
|
|
80
|
-
notify("patch object");
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
if (resetImpl) api.$reset = () => resetImpl();
|
|
84
|
-
const subs = /* @__PURE__ */ new Set();
|
|
85
|
-
api.$subscribe = (cb, _opts) => {
|
|
86
|
-
subs.add(cb);
|
|
87
|
-
return () => subs.delete(cb);
|
|
88
|
-
};
|
|
89
|
-
const actionSubs = /* @__PURE__ */ new Set();
|
|
90
|
-
api.$onAction = (cb) => {
|
|
91
|
-
actionSubs.add(cb);
|
|
92
|
-
return () => actionSubs.delete(cb);
|
|
93
|
-
};
|
|
94
|
-
return {
|
|
95
|
-
api,
|
|
96
|
-
subs,
|
|
97
|
-
actionSubs
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/store/manager.ts
|
|
103
|
-
function createStore() {
|
|
104
|
-
const manager = {
|
|
105
|
-
_stores: /* @__PURE__ */ new Map(),
|
|
106
|
-
_plugins: [],
|
|
107
|
-
install(_app) {},
|
|
108
|
-
use(plugin) {
|
|
109
|
-
if (typeof plugin === "function") manager._plugins.push(plugin);
|
|
110
|
-
return manager;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
createStore._instance = manager;
|
|
114
|
-
return manager;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/store/define.ts
|
|
119
|
-
function defineStore(id, setupOrOptions) {
|
|
120
|
-
let instance;
|
|
121
|
-
let created = false;
|
|
122
|
-
const manager = createStore._instance;
|
|
123
|
-
return function useStore() {
|
|
124
|
-
if (created && instance) return instance;
|
|
125
|
-
created = true;
|
|
126
|
-
if (typeof setupOrOptions === "function") {
|
|
127
|
-
const result = setupOrOptions();
|
|
128
|
-
let notify$1 = () => {};
|
|
129
|
-
const base$1 = createBaseApi(id, void 0, (t) => notify$1(t));
|
|
130
|
-
notify$1 = (type) => {
|
|
131
|
-
base$1.subs.forEach((cb) => {
|
|
132
|
-
try {
|
|
133
|
-
cb({
|
|
134
|
-
type,
|
|
135
|
-
storeId: id
|
|
136
|
-
}, instance);
|
|
137
|
-
} catch {}
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
instance = Object.assign({}, result);
|
|
141
|
-
for (const key of Object.getOwnPropertyNames(base$1.api)) {
|
|
142
|
-
const d = Object.getOwnPropertyDescriptor(base$1.api, key);
|
|
143
|
-
if (d) Object.defineProperty(instance, key, d);
|
|
144
|
-
}
|
|
145
|
-
Object.keys(result).forEach((k) => {
|
|
146
|
-
const val = result[k];
|
|
147
|
-
if (typeof val === "function" && !k.startsWith("$")) instance[k] = wrapAction(instance, k, val, base$1.actionSubs);
|
|
148
|
-
});
|
|
149
|
-
const plugins$1 = manager?._plugins ?? [];
|
|
150
|
-
for (const plugin of plugins$1) try {
|
|
151
|
-
plugin({ store: instance });
|
|
152
|
-
} catch {}
|
|
153
|
-
return instance;
|
|
154
|
-
}
|
|
155
|
-
const options = setupOrOptions;
|
|
156
|
-
const rawState = options.state ? options.state() : {};
|
|
157
|
-
const state = require_ref.reactive(rawState);
|
|
158
|
-
const initialSnapshot = { ...require_ref.toRaw(rawState) };
|
|
159
|
-
let notify = () => {};
|
|
160
|
-
const base = createBaseApi(id, state, (t) => notify(t), () => {
|
|
161
|
-
mergeShallow(state, initialSnapshot);
|
|
162
|
-
notify("patch object");
|
|
163
|
-
});
|
|
164
|
-
notify = (type) => {
|
|
165
|
-
base.subs.forEach((cb) => {
|
|
166
|
-
try {
|
|
167
|
-
cb({
|
|
168
|
-
type,
|
|
169
|
-
storeId: id
|
|
170
|
-
}, state);
|
|
171
|
-
} catch {}
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
const store = {};
|
|
175
|
-
for (const key of Object.getOwnPropertyNames(base.api)) {
|
|
176
|
-
const d = Object.getOwnPropertyDescriptor(base.api, key);
|
|
177
|
-
if (d) Object.defineProperty(store, key, d);
|
|
178
|
-
}
|
|
179
|
-
const getterDefs = options.getters ?? {};
|
|
180
|
-
const computedMap = {};
|
|
181
|
-
Object.keys(getterDefs).forEach((key) => {
|
|
182
|
-
const getter = getterDefs[key];
|
|
183
|
-
if (typeof getter === "function") {
|
|
184
|
-
const c = require_ref.computed(() => getter.call(store, state));
|
|
185
|
-
computedMap[key] = c;
|
|
186
|
-
Object.defineProperty(store, key, {
|
|
187
|
-
enumerable: true,
|
|
188
|
-
configurable: true,
|
|
189
|
-
get() {
|
|
190
|
-
return c.value;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
const actionDefs = options.actions ?? {};
|
|
196
|
-
Object.keys(actionDefs).forEach((key) => {
|
|
197
|
-
const act = actionDefs[key];
|
|
198
|
-
if (typeof act === "function") store[key] = wrapAction(store, key, (...args) => {
|
|
199
|
-
return act.apply(store, args);
|
|
200
|
-
}, base.actionSubs);
|
|
201
|
-
});
|
|
202
|
-
Object.keys(state).forEach((k) => {
|
|
203
|
-
Object.defineProperty(store, k, {
|
|
204
|
-
enumerable: true,
|
|
205
|
-
configurable: true,
|
|
206
|
-
get() {
|
|
207
|
-
return state[k];
|
|
208
|
-
},
|
|
209
|
-
set(v) {
|
|
210
|
-
state[k] = v;
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
instance = store;
|
|
215
|
-
const plugins = manager?._plugins ?? [];
|
|
216
|
-
for (const plugin of plugins) try {
|
|
217
|
-
plugin({ store: instance });
|
|
218
|
-
} catch {}
|
|
219
|
-
return instance;
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
//#endregion
|
|
224
|
-
//#region src/store/storeToRefs.ts
|
|
225
|
-
function storeToRefs(store) {
|
|
226
|
-
const result = {};
|
|
227
|
-
for (const key in store) {
|
|
228
|
-
const value = store[key];
|
|
229
|
-
if (typeof value === "function") {
|
|
230
|
-
result[key] = value;
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
if (require_ref.isRef(value)) result[key] = value;
|
|
234
|
-
else result[key] = require_ref.computed({
|
|
235
|
-
get: () => store[key],
|
|
236
|
-
set: (v) => {
|
|
237
|
-
store[key] = v;
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
return result;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
//#endregion
|
|
245
|
-
exports.createStore = createStore;
|
|
246
|
-
exports.defineStore = defineStore;
|
|
247
|
-
exports.storeToRefs = storeToRefs;
|
|
3
|
+
exports.createStore = require_store.createStore;
|
|
4
|
+
exports.defineStore = require_store.defineStore;
|
|
5
|
+
exports.storeToRefs = require_store.storeToRefs;
|
package/dist/store.d.cts
CHANGED
|
@@ -1,69 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
//#region src/store/types.d.ts
|
|
4
|
-
type MutationType = 'patch object' | 'patch function';
|
|
5
|
-
interface SubscriptionCallback<S = any> {
|
|
6
|
-
(mutation: {
|
|
7
|
-
type: MutationType;
|
|
8
|
-
storeId: string;
|
|
9
|
-
}, state: S): void;
|
|
10
|
-
}
|
|
11
|
-
interface ActionSubscriber<TStore = any> {
|
|
12
|
-
(context: {
|
|
13
|
-
name: string;
|
|
14
|
-
store: TStore;
|
|
15
|
-
args: any[];
|
|
16
|
-
after: (cb: (result: any) => void) => void;
|
|
17
|
-
onError: (cb: (error: any) => void) => void;
|
|
18
|
-
}): void;
|
|
19
|
-
}
|
|
20
|
-
interface StoreManager {
|
|
21
|
-
install: (app: any) => void;
|
|
22
|
-
_stores: Map<string, any>;
|
|
23
|
-
use: (plugin: (context: {
|
|
24
|
-
store: any;
|
|
25
|
-
}) => void) => StoreManager;
|
|
26
|
-
_plugins: Array<(context: {
|
|
27
|
-
store: any;
|
|
28
|
-
}) => void>;
|
|
29
|
-
}
|
|
30
|
-
interface DefineStoreOptions<S extends Record<string, any>, G extends Record<string, any>, A extends Record<string, any>> {
|
|
31
|
-
state: () => S;
|
|
32
|
-
getters?: G & ThisType<S & G & A>;
|
|
33
|
-
actions?: A & ThisType<S & G & A>;
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/store/define.d.ts
|
|
37
|
-
type SetupDefinition<T> = () => T;
|
|
38
|
-
declare function defineStore<T extends Record<string, any>>(id: string, setup: SetupDefinition<T>): () => T & {
|
|
39
|
-
$id: string;
|
|
40
|
-
$patch: (patch: Record<string, any> | ((state: any) => void)) => void;
|
|
41
|
-
$subscribe: (cb: (mutation: {
|
|
42
|
-
type: MutationType;
|
|
43
|
-
storeId: string;
|
|
44
|
-
}, state: any) => void, opts?: {
|
|
45
|
-
detached?: boolean;
|
|
46
|
-
}) => () => void;
|
|
47
|
-
$onAction: (cb: (context: any) => void) => () => void;
|
|
48
|
-
};
|
|
49
|
-
declare function defineStore<S extends Record<string, any>, G extends Record<string, any>, A extends Record<string, any>>(id: string, options: DefineStoreOptions<S, G, A>): () => S & G & A & {
|
|
50
|
-
$id: string;
|
|
51
|
-
$state: S;
|
|
52
|
-
$patch: (patch: Partial<S> | ((state: S) => void)) => void;
|
|
53
|
-
$reset: () => void;
|
|
54
|
-
$subscribe: (cb: (mutation: {
|
|
55
|
-
type: MutationType;
|
|
56
|
-
storeId: string;
|
|
57
|
-
}, state: S) => void, opts?: {
|
|
58
|
-
detached?: boolean;
|
|
59
|
-
}) => () => void;
|
|
60
|
-
$onAction: (cb: (context: any) => () => void) => () => void;
|
|
61
|
-
};
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/store/manager.d.ts
|
|
64
|
-
declare function createStore(): StoreManager;
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/store/storeToRefs.d.ts
|
|
67
|
-
declare function storeToRefs<T extends Record<string, any>>(store: T): { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? T[K] : Ref<T[K]> };
|
|
68
|
-
//#endregion
|
|
69
|
-
export { type ActionSubscriber, type DefineStoreOptions, type MutationType, type StoreManager, type SubscriptionCallback, createStore, defineStore, storeToRefs };
|
|
1
|
+
import { a as DefineStoreOptions, c as SubscriptionCallback, i as ActionSubscriber, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs } from "./index-DVEFI-Uo.cjs";
|
|
2
|
+
export { ActionSubscriber, DefineStoreOptions, MutationType, StoreManager, SubscriptionCallback, createStore, defineStore, storeToRefs };
|
package/dist/store.d.mts
CHANGED
|
@@ -1,69 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
//#region src/store/types.d.ts
|
|
4
|
-
type MutationType = 'patch object' | 'patch function';
|
|
5
|
-
interface SubscriptionCallback<S = any> {
|
|
6
|
-
(mutation: {
|
|
7
|
-
type: MutationType;
|
|
8
|
-
storeId: string;
|
|
9
|
-
}, state: S): void;
|
|
10
|
-
}
|
|
11
|
-
interface ActionSubscriber<TStore = any> {
|
|
12
|
-
(context: {
|
|
13
|
-
name: string;
|
|
14
|
-
store: TStore;
|
|
15
|
-
args: any[];
|
|
16
|
-
after: (cb: (result: any) => void) => void;
|
|
17
|
-
onError: (cb: (error: any) => void) => void;
|
|
18
|
-
}): void;
|
|
19
|
-
}
|
|
20
|
-
interface StoreManager {
|
|
21
|
-
install: (app: any) => void;
|
|
22
|
-
_stores: Map<string, any>;
|
|
23
|
-
use: (plugin: (context: {
|
|
24
|
-
store: any;
|
|
25
|
-
}) => void) => StoreManager;
|
|
26
|
-
_plugins: Array<(context: {
|
|
27
|
-
store: any;
|
|
28
|
-
}) => void>;
|
|
29
|
-
}
|
|
30
|
-
interface DefineStoreOptions<S extends Record<string, any>, G extends Record<string, any>, A extends Record<string, any>> {
|
|
31
|
-
state: () => S;
|
|
32
|
-
getters?: G & ThisType<S & G & A>;
|
|
33
|
-
actions?: A & ThisType<S & G & A>;
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/store/define.d.ts
|
|
37
|
-
type SetupDefinition<T> = () => T;
|
|
38
|
-
declare function defineStore<T extends Record<string, any>>(id: string, setup: SetupDefinition<T>): () => T & {
|
|
39
|
-
$id: string;
|
|
40
|
-
$patch: (patch: Record<string, any> | ((state: any) => void)) => void;
|
|
41
|
-
$subscribe: (cb: (mutation: {
|
|
42
|
-
type: MutationType;
|
|
43
|
-
storeId: string;
|
|
44
|
-
}, state: any) => void, opts?: {
|
|
45
|
-
detached?: boolean;
|
|
46
|
-
}) => () => void;
|
|
47
|
-
$onAction: (cb: (context: any) => void) => () => void;
|
|
48
|
-
};
|
|
49
|
-
declare function defineStore<S extends Record<string, any>, G extends Record<string, any>, A extends Record<string, any>>(id: string, options: DefineStoreOptions<S, G, A>): () => S & G & A & {
|
|
50
|
-
$id: string;
|
|
51
|
-
$state: S;
|
|
52
|
-
$patch: (patch: Partial<S> | ((state: S) => void)) => void;
|
|
53
|
-
$reset: () => void;
|
|
54
|
-
$subscribe: (cb: (mutation: {
|
|
55
|
-
type: MutationType;
|
|
56
|
-
storeId: string;
|
|
57
|
-
}, state: S) => void, opts?: {
|
|
58
|
-
detached?: boolean;
|
|
59
|
-
}) => () => void;
|
|
60
|
-
$onAction: (cb: (context: any) => () => void) => () => void;
|
|
61
|
-
};
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/store/manager.d.ts
|
|
64
|
-
declare function createStore(): StoreManager;
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/store/storeToRefs.d.ts
|
|
67
|
-
declare function storeToRefs<T extends Record<string, any>>(store: T): { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? T[K] : Ref<T[K]> };
|
|
68
|
-
//#endregion
|
|
69
|
-
export { type ActionSubscriber, type DefineStoreOptions, type MutationType, type StoreManager, type SubscriptionCallback, createStore, defineStore, storeToRefs };
|
|
1
|
+
import { a as DefineStoreOptions, c as SubscriptionCallback, i as ActionSubscriber, n as createStore, o as MutationType, r as defineStore, s as StoreManager, t as storeToRefs } from "./index-0dF4y5p6.mjs";
|
|
2
|
+
export { ActionSubscriber, DefineStoreOptions, MutationType, StoreManager, SubscriptionCallback, createStore, defineStore, storeToRefs };
|
package/dist/store.mjs
CHANGED
|
@@ -1,245 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as defineStore, r as createStore, t as storeToRefs } from "./store-BcU7YVhB.mjs";
|
|
2
2
|
|
|
3
|
-
//#region src/store/actions.ts
|
|
4
|
-
function wrapAction(store, name, action, actionSubs) {
|
|
5
|
-
return function wrapped(...args) {
|
|
6
|
-
const afterCbs = [];
|
|
7
|
-
const errorCbs = [];
|
|
8
|
-
const after = (cb) => afterCbs.push(cb);
|
|
9
|
-
const onError = (cb) => errorCbs.push(cb);
|
|
10
|
-
actionSubs.forEach((sub) => {
|
|
11
|
-
try {
|
|
12
|
-
sub({
|
|
13
|
-
name,
|
|
14
|
-
store,
|
|
15
|
-
args,
|
|
16
|
-
after,
|
|
17
|
-
onError
|
|
18
|
-
});
|
|
19
|
-
} catch {}
|
|
20
|
-
});
|
|
21
|
-
let res;
|
|
22
|
-
try {
|
|
23
|
-
res = action.apply(store, args);
|
|
24
|
-
} catch (e) {
|
|
25
|
-
errorCbs.forEach((cb) => cb(e));
|
|
26
|
-
throw e;
|
|
27
|
-
}
|
|
28
|
-
const finalize = (r) => {
|
|
29
|
-
afterCbs.forEach((cb) => cb(r));
|
|
30
|
-
return r;
|
|
31
|
-
};
|
|
32
|
-
if (res && typeof res.then === "function") return res.then((r) => finalize(r), (e) => {
|
|
33
|
-
errorCbs.forEach((cb) => cb(e));
|
|
34
|
-
return Promise.reject(e);
|
|
35
|
-
});
|
|
36
|
-
return finalize(res);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/store/utils.ts
|
|
42
|
-
function isObject(val) {
|
|
43
|
-
return typeof val === "object" && val !== null;
|
|
44
|
-
}
|
|
45
|
-
function mergeShallow(target, patch) {
|
|
46
|
-
for (const k in patch) target[k] = patch[k];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region src/store/base.ts
|
|
51
|
-
function createBaseApi(id, stateObj, notify, resetImpl) {
|
|
52
|
-
const api = { $id: id };
|
|
53
|
-
Object.defineProperty(api, "$state", {
|
|
54
|
-
get() {
|
|
55
|
-
return stateObj;
|
|
56
|
-
},
|
|
57
|
-
set(v) {
|
|
58
|
-
if (stateObj && isObject(v)) {
|
|
59
|
-
mergeShallow(stateObj, v);
|
|
60
|
-
notify("patch object");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
api.$patch = (patch) => {
|
|
65
|
-
if (!stateObj) {
|
|
66
|
-
if (typeof patch === "function") {
|
|
67
|
-
patch(api);
|
|
68
|
-
notify("patch function");
|
|
69
|
-
} else {
|
|
70
|
-
mergeShallow(api, patch);
|
|
71
|
-
notify("patch object");
|
|
72
|
-
}
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (typeof patch === "function") {
|
|
76
|
-
patch(stateObj);
|
|
77
|
-
notify("patch function");
|
|
78
|
-
} else {
|
|
79
|
-
mergeShallow(stateObj, patch);
|
|
80
|
-
notify("patch object");
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
if (resetImpl) api.$reset = () => resetImpl();
|
|
84
|
-
const subs = /* @__PURE__ */ new Set();
|
|
85
|
-
api.$subscribe = (cb, _opts) => {
|
|
86
|
-
subs.add(cb);
|
|
87
|
-
return () => subs.delete(cb);
|
|
88
|
-
};
|
|
89
|
-
const actionSubs = /* @__PURE__ */ new Set();
|
|
90
|
-
api.$onAction = (cb) => {
|
|
91
|
-
actionSubs.add(cb);
|
|
92
|
-
return () => actionSubs.delete(cb);
|
|
93
|
-
};
|
|
94
|
-
return {
|
|
95
|
-
api,
|
|
96
|
-
subs,
|
|
97
|
-
actionSubs
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/store/manager.ts
|
|
103
|
-
function createStore() {
|
|
104
|
-
const manager = {
|
|
105
|
-
_stores: /* @__PURE__ */ new Map(),
|
|
106
|
-
_plugins: [],
|
|
107
|
-
install(_app) {},
|
|
108
|
-
use(plugin) {
|
|
109
|
-
if (typeof plugin === "function") manager._plugins.push(plugin);
|
|
110
|
-
return manager;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
createStore._instance = manager;
|
|
114
|
-
return manager;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/store/define.ts
|
|
119
|
-
function defineStore(id, setupOrOptions) {
|
|
120
|
-
let instance;
|
|
121
|
-
let created = false;
|
|
122
|
-
const manager = createStore._instance;
|
|
123
|
-
return function useStore() {
|
|
124
|
-
if (created && instance) return instance;
|
|
125
|
-
created = true;
|
|
126
|
-
if (typeof setupOrOptions === "function") {
|
|
127
|
-
const result = setupOrOptions();
|
|
128
|
-
let notify$1 = () => {};
|
|
129
|
-
const base$1 = createBaseApi(id, void 0, (t) => notify$1(t));
|
|
130
|
-
notify$1 = (type) => {
|
|
131
|
-
base$1.subs.forEach((cb) => {
|
|
132
|
-
try {
|
|
133
|
-
cb({
|
|
134
|
-
type,
|
|
135
|
-
storeId: id
|
|
136
|
-
}, instance);
|
|
137
|
-
} catch {}
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
instance = Object.assign({}, result);
|
|
141
|
-
for (const key of Object.getOwnPropertyNames(base$1.api)) {
|
|
142
|
-
const d = Object.getOwnPropertyDescriptor(base$1.api, key);
|
|
143
|
-
if (d) Object.defineProperty(instance, key, d);
|
|
144
|
-
}
|
|
145
|
-
Object.keys(result).forEach((k) => {
|
|
146
|
-
const val = result[k];
|
|
147
|
-
if (typeof val === "function" && !k.startsWith("$")) instance[k] = wrapAction(instance, k, val, base$1.actionSubs);
|
|
148
|
-
});
|
|
149
|
-
const plugins$1 = manager?._plugins ?? [];
|
|
150
|
-
for (const plugin of plugins$1) try {
|
|
151
|
-
plugin({ store: instance });
|
|
152
|
-
} catch {}
|
|
153
|
-
return instance;
|
|
154
|
-
}
|
|
155
|
-
const options = setupOrOptions;
|
|
156
|
-
const rawState = options.state ? options.state() : {};
|
|
157
|
-
const state = reactive(rawState);
|
|
158
|
-
const initialSnapshot = { ...toRaw(rawState) };
|
|
159
|
-
let notify = () => {};
|
|
160
|
-
const base = createBaseApi(id, state, (t) => notify(t), () => {
|
|
161
|
-
mergeShallow(state, initialSnapshot);
|
|
162
|
-
notify("patch object");
|
|
163
|
-
});
|
|
164
|
-
notify = (type) => {
|
|
165
|
-
base.subs.forEach((cb) => {
|
|
166
|
-
try {
|
|
167
|
-
cb({
|
|
168
|
-
type,
|
|
169
|
-
storeId: id
|
|
170
|
-
}, state);
|
|
171
|
-
} catch {}
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
const store = {};
|
|
175
|
-
for (const key of Object.getOwnPropertyNames(base.api)) {
|
|
176
|
-
const d = Object.getOwnPropertyDescriptor(base.api, key);
|
|
177
|
-
if (d) Object.defineProperty(store, key, d);
|
|
178
|
-
}
|
|
179
|
-
const getterDefs = options.getters ?? {};
|
|
180
|
-
const computedMap = {};
|
|
181
|
-
Object.keys(getterDefs).forEach((key) => {
|
|
182
|
-
const getter = getterDefs[key];
|
|
183
|
-
if (typeof getter === "function") {
|
|
184
|
-
const c = computed(() => getter.call(store, state));
|
|
185
|
-
computedMap[key] = c;
|
|
186
|
-
Object.defineProperty(store, key, {
|
|
187
|
-
enumerable: true,
|
|
188
|
-
configurable: true,
|
|
189
|
-
get() {
|
|
190
|
-
return c.value;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
const actionDefs = options.actions ?? {};
|
|
196
|
-
Object.keys(actionDefs).forEach((key) => {
|
|
197
|
-
const act = actionDefs[key];
|
|
198
|
-
if (typeof act === "function") store[key] = wrapAction(store, key, (...args) => {
|
|
199
|
-
return act.apply(store, args);
|
|
200
|
-
}, base.actionSubs);
|
|
201
|
-
});
|
|
202
|
-
Object.keys(state).forEach((k) => {
|
|
203
|
-
Object.defineProperty(store, k, {
|
|
204
|
-
enumerable: true,
|
|
205
|
-
configurable: true,
|
|
206
|
-
get() {
|
|
207
|
-
return state[k];
|
|
208
|
-
},
|
|
209
|
-
set(v) {
|
|
210
|
-
state[k] = v;
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
instance = store;
|
|
215
|
-
const plugins = manager?._plugins ?? [];
|
|
216
|
-
for (const plugin of plugins) try {
|
|
217
|
-
plugin({ store: instance });
|
|
218
|
-
} catch {}
|
|
219
|
-
return instance;
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
//#endregion
|
|
224
|
-
//#region src/store/storeToRefs.ts
|
|
225
|
-
function storeToRefs(store) {
|
|
226
|
-
const result = {};
|
|
227
|
-
for (const key in store) {
|
|
228
|
-
const value = store[key];
|
|
229
|
-
if (typeof value === "function") {
|
|
230
|
-
result[key] = value;
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
if (isRef(value)) result[key] = value;
|
|
234
|
-
else result[key] = computed({
|
|
235
|
-
get: () => store[key],
|
|
236
|
-
set: (v) => {
|
|
237
|
-
store[key] = v;
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
return result;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
//#endregion
|
|
245
3
|
export { createStore, defineStore, storeToRefs };
|
package/package.json
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wevu",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.1",
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "1.0.0-alpha.1",
|
|
5
|
+
"description": "Vue 3 风格的小程序运行时,包含响应式、diff+setData 与轻量状态管理",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
|
-
"license": "
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/weapp-vite/weapp-vite/tree/main/packages/wevu",
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
|
10
11
|
"url": "git+https://github.com/weapp-vite/weapp-vite.git",
|
|
11
|
-
"directory": "packages/
|
|
12
|
+
"directory": "packages/wevu"
|
|
12
13
|
},
|
|
13
14
|
"bugs": {
|
|
14
15
|
"url": "https://github.com/weapp-vite/weapp-vite/issues"
|
|
15
16
|
},
|
|
16
|
-
"keywords": [
|
|
17
|
+
"keywords": [
|
|
18
|
+
"weapp",
|
|
19
|
+
"mini-program",
|
|
20
|
+
"wechat",
|
|
21
|
+
"vue3",
|
|
22
|
+
"runtime",
|
|
23
|
+
"reactivity",
|
|
24
|
+
"setData",
|
|
25
|
+
"pinia",
|
|
26
|
+
"state-management"
|
|
27
|
+
],
|
|
17
28
|
"sideEffects": false,
|
|
18
29
|
"exports": {
|
|
19
30
|
".": {
|
|
@@ -26,17 +37,6 @@
|
|
|
26
37
|
"types": "./dist/index.d.cts",
|
|
27
38
|
"default": "./dist/index.cjs"
|
|
28
39
|
}
|
|
29
|
-
},
|
|
30
|
-
"./store": {
|
|
31
|
-
"types": "./dist/store.d.mts",
|
|
32
|
-
"import": {
|
|
33
|
-
"types": "./dist/store.d.mts",
|
|
34
|
-
"default": "./dist/store.mjs"
|
|
35
|
-
},
|
|
36
|
-
"require": {
|
|
37
|
-
"types": "./dist/store.d.cts",
|
|
38
|
-
"default": "./dist/store.cjs"
|
|
39
|
-
}
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"main": "./dist/index.cjs",
|
|
@@ -45,11 +45,19 @@
|
|
|
45
45
|
"files": [
|
|
46
46
|
"dist"
|
|
47
47
|
],
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"registry": "https://registry.npmjs.org"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=20.19.0"
|
|
54
|
+
},
|
|
48
55
|
"scripts": {
|
|
49
56
|
"dev": "tsdown -w",
|
|
50
57
|
"build": "tsdown",
|
|
51
58
|
"test": "vitest run",
|
|
52
59
|
"test:dev": "vitest",
|
|
60
|
+
"test:types": "tsd",
|
|
53
61
|
"release": "pnpm publish",
|
|
54
62
|
"lint": "eslint .",
|
|
55
63
|
"lint:fix": "eslint . --fix"
|