pinia-react 2.1.2 → 2.1.3
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/index.cjs +508 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +106 -0
- package/dist/index.d.ts +12 -7
- package/dist/index.js +132 -32
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createPinia: () => createPinia,
|
|
24
|
+
defineStore: () => defineStore,
|
|
25
|
+
getActivePinia: () => getActivePinia,
|
|
26
|
+
setActivePinia: () => setActivePinia
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/rootStore.ts
|
|
31
|
+
var activePinia;
|
|
32
|
+
function setActivePinia(pinia) {
|
|
33
|
+
activePinia = pinia;
|
|
34
|
+
}
|
|
35
|
+
function getActivePinia() {
|
|
36
|
+
if (!activePinia) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
"[pinia-react] getActivePinia was called with no active Pinia. Did you forget to install pinia?\nconst pinia = createPinia() or createPinia() first.\n"
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return activePinia;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/createPinia.ts
|
|
45
|
+
function createPinia() {
|
|
46
|
+
const state = {};
|
|
47
|
+
const _p = [];
|
|
48
|
+
const _s = /* @__PURE__ */ new Map();
|
|
49
|
+
const _scopes = /* @__PURE__ */ new Map();
|
|
50
|
+
const _m = /* @__PURE__ */ new Set();
|
|
51
|
+
const pinia = {
|
|
52
|
+
use(plugin) {
|
|
53
|
+
if (_s.size > 0) {
|
|
54
|
+
console.warn(
|
|
55
|
+
"[pinia-react] A plugin was registered after stores were created. The new plugin will not be applied to the stores that already exist."
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
_p.push(plugin);
|
|
59
|
+
return this;
|
|
60
|
+
},
|
|
61
|
+
onMutation(listener) {
|
|
62
|
+
_m.add(listener);
|
|
63
|
+
return () => _m.delete(listener);
|
|
64
|
+
},
|
|
65
|
+
_p,
|
|
66
|
+
_s,
|
|
67
|
+
_scopes,
|
|
68
|
+
_m,
|
|
69
|
+
state
|
|
70
|
+
};
|
|
71
|
+
setActivePinia(pinia);
|
|
72
|
+
return pinia;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/store.ts
|
|
76
|
+
var import_immer = require("immer");
|
|
77
|
+
var import_react = require("react");
|
|
78
|
+
(0, import_immer.enablePatches)();
|
|
79
|
+
var immer = new import_immer.Immer({ autoFreeze: false });
|
|
80
|
+
var activeListenerId = null;
|
|
81
|
+
var activeGetterKey = null;
|
|
82
|
+
var storeDefinitionByPinia = /* @__PURE__ */ new WeakMap();
|
|
83
|
+
function isAffected(patches, trackedPaths) {
|
|
84
|
+
if (trackedPaths.size === 0) return false;
|
|
85
|
+
const tracked = Array.from(trackedPaths);
|
|
86
|
+
for (const patch of patches) {
|
|
87
|
+
const patchPath = patch.path.map(String);
|
|
88
|
+
for (const trackedPath of tracked) {
|
|
89
|
+
const len = Math.min(patchPath.length, trackedPath.length);
|
|
90
|
+
let isPrefixMatch = true;
|
|
91
|
+
for (let i = 0; i < len; i++) {
|
|
92
|
+
if (patchPath[i] !== trackedPath[i]) {
|
|
93
|
+
isPrefixMatch = false;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (isPrefixMatch) return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
function isPlainObjectOrArray(value) {
|
|
103
|
+
if (Array.isArray(value)) return true;
|
|
104
|
+
if (value === null || typeof value !== "object") return false;
|
|
105
|
+
const proto = Object.getPrototypeOf(value);
|
|
106
|
+
return proto === Object.prototype || proto === null;
|
|
107
|
+
}
|
|
108
|
+
function defineStore(id, options) {
|
|
109
|
+
const getters = options.getters || {};
|
|
110
|
+
function ensureStoreInstance(pinia) {
|
|
111
|
+
if (pinia._s.has(id)) {
|
|
112
|
+
if (storeDefinitionByPinia.get(pinia)?.get(id) === options) return;
|
|
113
|
+
console.warn(
|
|
114
|
+
`[pinia-react] Duplicate store id "${id}" detected. The new definition replaces the previous store with the same id.`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
createStoreInstance();
|
|
118
|
+
}
|
|
119
|
+
function resolveGetterDependencies(getterName, getterDepsMap, visited = /* @__PURE__ */ new Set()) {
|
|
120
|
+
if (visited.has(getterName)) {
|
|
121
|
+
console.warn(`[pinia-react] Circular dependency in getters detected involving: ${getterName}`);
|
|
122
|
+
return /* @__PURE__ */ new Set();
|
|
123
|
+
}
|
|
124
|
+
visited.add(getterName);
|
|
125
|
+
const finalDeps = /* @__PURE__ */ new Set();
|
|
126
|
+
const directDeps = getterDepsMap.get(getterName);
|
|
127
|
+
if (!directDeps) return finalDeps;
|
|
128
|
+
for (const dep of directDeps) {
|
|
129
|
+
const getterKey = dep.length === 1 ? dep[0] : void 0;
|
|
130
|
+
if (getterKey && getterKey in getters) {
|
|
131
|
+
const nestedDeps = resolveGetterDependencies(getterKey, getterDepsMap, visited);
|
|
132
|
+
nestedDeps.forEach((d) => finalDeps.add(d));
|
|
133
|
+
} else {
|
|
134
|
+
finalDeps.add(dep);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return finalDeps;
|
|
138
|
+
}
|
|
139
|
+
function createStoreInstance() {
|
|
140
|
+
const pinia = getActivePinia();
|
|
141
|
+
const initialState = options.state();
|
|
142
|
+
let storePublicApi;
|
|
143
|
+
const localScope = {
|
|
144
|
+
currentState: initialState,
|
|
145
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
146
|
+
getterResultCache: /* @__PURE__ */ new Map(),
|
|
147
|
+
getterDependencies: /* @__PURE__ */ new Map(),
|
|
148
|
+
subscribers: /* @__PURE__ */ new Map(),
|
|
149
|
+
createStoreProxy: (_onAccess) => storePublicApi
|
|
150
|
+
};
|
|
151
|
+
pinia._scopes.set(id, localScope);
|
|
152
|
+
let definitionsById = storeDefinitionByPinia.get(pinia);
|
|
153
|
+
if (!definitionsById) {
|
|
154
|
+
definitionsById = /* @__PURE__ */ new Map();
|
|
155
|
+
storeDefinitionByPinia.set(pinia, definitionsById);
|
|
156
|
+
}
|
|
157
|
+
definitionsById.set(id, options);
|
|
158
|
+
const isGetterComputing = /* @__PURE__ */ new Set();
|
|
159
|
+
const emit = (nextState, oldState, patches) => {
|
|
160
|
+
localScope.listeners.forEach((fn) => fn(nextState, oldState, patches));
|
|
161
|
+
localScope.subscribers.forEach((getterKeys, storeId) => {
|
|
162
|
+
const subscriberScope = pinia._scopes.get(storeId);
|
|
163
|
+
if (!subscriberScope) return;
|
|
164
|
+
let shouldNotify = false;
|
|
165
|
+
getterKeys.forEach((key) => {
|
|
166
|
+
if (subscriberScope.getterResultCache.has(key)) {
|
|
167
|
+
subscriberScope.getterResultCache.delete(key);
|
|
168
|
+
shouldNotify = true;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
if (shouldNotify) {
|
|
172
|
+
const oldSubState = subscriberScope.currentState;
|
|
173
|
+
const newSubState = { ...oldSubState };
|
|
174
|
+
subscriberScope.currentState = newSubState;
|
|
175
|
+
pinia.state[storeId] = newSubState;
|
|
176
|
+
subscriberScope.listeners.forEach((fn) => fn(newSubState, oldSubState, []));
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
const internalPatch = (updater, meta) => {
|
|
181
|
+
const oldState = localScope.currentState;
|
|
182
|
+
let patches = [];
|
|
183
|
+
const nextState = immer.produce(oldState, updater, (p) => {
|
|
184
|
+
patches = p;
|
|
185
|
+
});
|
|
186
|
+
if (patches.length > 0 || meta.type === "reset") {
|
|
187
|
+
localScope.currentState = nextState;
|
|
188
|
+
pinia.state[id] = nextState;
|
|
189
|
+
emit(nextState, oldState, patches);
|
|
190
|
+
const event = {
|
|
191
|
+
storeId: id,
|
|
192
|
+
store: storePublicApi,
|
|
193
|
+
state: nextState,
|
|
194
|
+
prevState: oldState,
|
|
195
|
+
patches,
|
|
196
|
+
meta
|
|
197
|
+
};
|
|
198
|
+
pinia._m.forEach((listener) => listener(event));
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const $patch = (updater) => {
|
|
202
|
+
internalPatch(
|
|
203
|
+
(draft) => {
|
|
204
|
+
updater(draft);
|
|
205
|
+
},
|
|
206
|
+
{ type: "patch" }
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
const $reset = () => internalPatch(() => options.state(), { type: "reset" });
|
|
210
|
+
const restoreState = (state, options2 = {}) => {
|
|
211
|
+
internalPatch(() => state, {
|
|
212
|
+
type: options2.type ?? "restore",
|
|
213
|
+
origin: options2.origin
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
const $subscribe = (callback) => {
|
|
217
|
+
const listener = (state, prev) => callback(state, prev);
|
|
218
|
+
localScope.listeners.add(listener);
|
|
219
|
+
return () => localScope.listeners.delete(listener);
|
|
220
|
+
};
|
|
221
|
+
const getterInvalidationListener = (_state, _prevState, patches) => {
|
|
222
|
+
localScope.getterDependencies.forEach((_deps, getterName) => {
|
|
223
|
+
const resolvedDeps = resolveGetterDependencies(getterName, localScope.getterDependencies);
|
|
224
|
+
if (isAffected(patches, resolvedDeps)) {
|
|
225
|
+
localScope.getterResultCache.delete(getterName);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
localScope.listeners.add(getterInvalidationListener);
|
|
230
|
+
const originalActions = options.actions || {};
|
|
231
|
+
const wrappedActions = {};
|
|
232
|
+
const proxyTarget = {};
|
|
233
|
+
const readonlyStateProxyCache = /* @__PURE__ */ new WeakMap();
|
|
234
|
+
const readonlyWarning = () => {
|
|
235
|
+
console.warn(`[${id}] Store is read-only. Use actions for mutations.`);
|
|
236
|
+
throw new TypeError(`[${id}] Store is read-only. Use actions for mutations.`);
|
|
237
|
+
};
|
|
238
|
+
const createReadonlyStateProxy = (stateTarget) => {
|
|
239
|
+
const cached = readonlyStateProxyCache.get(stateTarget);
|
|
240
|
+
if (cached) return cached;
|
|
241
|
+
const proxy = new Proxy(stateTarget, {
|
|
242
|
+
get(obj, key) {
|
|
243
|
+
const value = Reflect.get(obj, key);
|
|
244
|
+
if (isPlainObjectOrArray(value)) return createReadonlyStateProxy(value);
|
|
245
|
+
return value;
|
|
246
|
+
},
|
|
247
|
+
set: readonlyWarning,
|
|
248
|
+
deleteProperty: readonlyWarning
|
|
249
|
+
});
|
|
250
|
+
readonlyStateProxyCache.set(stateTarget, proxy);
|
|
251
|
+
return proxy;
|
|
252
|
+
};
|
|
253
|
+
const getAtPath = (path) => {
|
|
254
|
+
let value = localScope.currentState;
|
|
255
|
+
for (const key of path) value = value[key];
|
|
256
|
+
return value;
|
|
257
|
+
};
|
|
258
|
+
const setAtPath = (draft, path, value) => {
|
|
259
|
+
let target = draft;
|
|
260
|
+
for (let i = 0; i < path.length - 1; i++) target = target[path[i]];
|
|
261
|
+
target[path[path.length - 1]] = value;
|
|
262
|
+
};
|
|
263
|
+
const deleteAtPath = (draft, path) => {
|
|
264
|
+
let target = draft;
|
|
265
|
+
for (let i = 0; i < path.length - 1; i++) target = target[path[i]];
|
|
266
|
+
delete target[path[path.length - 1]];
|
|
267
|
+
};
|
|
268
|
+
const createActionStateProxy = (path, meta) => {
|
|
269
|
+
return new Proxy(Array.isArray(getAtPath(path)) ? [] : {}, {
|
|
270
|
+
get(_target, key, receiver) {
|
|
271
|
+
const current = getAtPath(path);
|
|
272
|
+
const value = Reflect.get(current, key, receiver);
|
|
273
|
+
if (typeof key === "symbol" || !isPlainObjectOrArray(value)) return value;
|
|
274
|
+
return createActionStateProxy([...path, String(key)], meta);
|
|
275
|
+
},
|
|
276
|
+
set(_target, key, value) {
|
|
277
|
+
internalPatch((draft) => setAtPath(draft, [...path, String(key)], value), meta);
|
|
278
|
+
return true;
|
|
279
|
+
},
|
|
280
|
+
deleteProperty(_target, key) {
|
|
281
|
+
internalPatch((draft) => deleteAtPath(draft, [...path, String(key)]), meta);
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
function createStoreProxy(onAccess) {
|
|
287
|
+
const createStateProxy = (stateTarget, path, onDeepAccess, trackObjectAccess = false) => {
|
|
288
|
+
return new Proxy(stateTarget, {
|
|
289
|
+
get(obj, key) {
|
|
290
|
+
if (typeof key === "symbol") return Reflect.get(obj, key);
|
|
291
|
+
const currentPath = [...path, String(key)];
|
|
292
|
+
const value = Reflect.get(obj, key);
|
|
293
|
+
if (isPlainObjectOrArray(value)) {
|
|
294
|
+
if (trackObjectAccess) onDeepAccess?.(currentPath);
|
|
295
|
+
return createStateProxy(value, currentPath, onDeepAccess, trackObjectAccess);
|
|
296
|
+
}
|
|
297
|
+
onDeepAccess?.(currentPath);
|
|
298
|
+
return value;
|
|
299
|
+
},
|
|
300
|
+
set: readonlyWarning,
|
|
301
|
+
deleteProperty: readonlyWarning
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
return new Proxy(proxyTarget, {
|
|
305
|
+
get(_target, key, receiver) {
|
|
306
|
+
const strKey = String(key);
|
|
307
|
+
if (strKey === "$state") {
|
|
308
|
+
onAccess?.(["$state"]);
|
|
309
|
+
return createReadonlyStateProxy(localScope.currentState);
|
|
310
|
+
}
|
|
311
|
+
if (strKey === "$id") return id;
|
|
312
|
+
if (strKey === "$patch") return $patch;
|
|
313
|
+
if (strKey === "$reset") return $reset;
|
|
314
|
+
if (strKey === "$subscribe") return $subscribe;
|
|
315
|
+
const state = localScope.currentState;
|
|
316
|
+
if (strKey in state) {
|
|
317
|
+
const value = state[strKey];
|
|
318
|
+
if (isPlainObjectOrArray(value)) {
|
|
319
|
+
return createStateProxy(value, [strKey], onAccess);
|
|
320
|
+
}
|
|
321
|
+
onAccess?.([strKey]);
|
|
322
|
+
return value;
|
|
323
|
+
}
|
|
324
|
+
if (strKey in getters) {
|
|
325
|
+
onAccess?.([strKey]);
|
|
326
|
+
if (localScope.getterResultCache.has(strKey)) return localScope.getterResultCache.get(strKey);
|
|
327
|
+
if (isGetterComputing.has(strKey)) {
|
|
328
|
+
console.warn(`[pinia-react] Circular dependency detected in getter "${strKey}"`);
|
|
329
|
+
return void 0;
|
|
330
|
+
}
|
|
331
|
+
isGetterComputing.add(strKey);
|
|
332
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
333
|
+
const prevListenerId = activeListenerId;
|
|
334
|
+
const prevGetterKey = activeGetterKey;
|
|
335
|
+
activeListenerId = id;
|
|
336
|
+
activeGetterKey = strKey;
|
|
337
|
+
try {
|
|
338
|
+
const onGetterAccess = (path) => {
|
|
339
|
+
dependencies.add(path);
|
|
340
|
+
};
|
|
341
|
+
const trackingProxyForThis = createStoreProxy(onGetterAccess);
|
|
342
|
+
const trackingStateProxy = createStateProxy(state, [], onGetterAccess, true);
|
|
343
|
+
const result = getters[strKey].call(trackingProxyForThis, trackingStateProxy);
|
|
344
|
+
localScope.getterDependencies.set(strKey, dependencies);
|
|
345
|
+
localScope.getterResultCache.set(strKey, result);
|
|
346
|
+
return result;
|
|
347
|
+
} finally {
|
|
348
|
+
activeListenerId = prevListenerId;
|
|
349
|
+
activeGetterKey = prevGetterKey;
|
|
350
|
+
isGetterComputing.delete(strKey);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
if (strKey in wrappedActions) {
|
|
354
|
+
return wrappedActions[strKey];
|
|
355
|
+
}
|
|
356
|
+
return Reflect.get(_target, key, receiver);
|
|
357
|
+
},
|
|
358
|
+
set(_target, key, value, receiver) {
|
|
359
|
+
const strKey = String(key);
|
|
360
|
+
if (strKey === "$state") {
|
|
361
|
+
console.warn(`[${id}] Do not replace "$state" directly. Use "$patch()" to replace the whole state.`);
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
if (strKey === "$id") return readonlyWarning();
|
|
365
|
+
if (strKey in localScope.currentState || strKey in getters || strKey in wrappedActions) {
|
|
366
|
+
return readonlyWarning();
|
|
367
|
+
}
|
|
368
|
+
return Reflect.set(_target, key, value, receiver);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
storePublicApi = createStoreProxy();
|
|
373
|
+
Object.keys(originalActions).forEach((actionName) => {
|
|
374
|
+
const originalAction = originalActions[actionName];
|
|
375
|
+
wrappedActions[actionName] = (...args) => {
|
|
376
|
+
let returnValue;
|
|
377
|
+
let draftActive = true;
|
|
378
|
+
const meta = { type: "action", action: actionName, args };
|
|
379
|
+
const recipe = (draft) => {
|
|
380
|
+
const actionContextProxy = new Proxy({}, {
|
|
381
|
+
get(_, key) {
|
|
382
|
+
const strKey = String(key);
|
|
383
|
+
if (draftActive && Reflect.has(draft, strKey)) return draft[strKey];
|
|
384
|
+
if (!draftActive && Reflect.has(localScope.currentState, strKey)) {
|
|
385
|
+
const value = localScope.currentState[strKey];
|
|
386
|
+
if (value !== null && typeof value === "object") return createActionStateProxy([strKey], meta);
|
|
387
|
+
return value;
|
|
388
|
+
}
|
|
389
|
+
if (strKey in getters) {
|
|
390
|
+
if (draftActive) return getters[strKey].call(actionContextProxy, draft);
|
|
391
|
+
return Reflect.get(storePublicApi, key, storePublicApi);
|
|
392
|
+
}
|
|
393
|
+
return Reflect.get(storePublicApi, key, storePublicApi);
|
|
394
|
+
},
|
|
395
|
+
set(_, key, value) {
|
|
396
|
+
const path = [String(key)];
|
|
397
|
+
if (draftActive) draft[path[0]] = value;
|
|
398
|
+
else internalPatch((currentDraft) => setAtPath(currentDraft, path, value), meta);
|
|
399
|
+
return true;
|
|
400
|
+
},
|
|
401
|
+
deleteProperty(_, key) {
|
|
402
|
+
const path = [String(key)];
|
|
403
|
+
if (draftActive) delete draft[path[0]];
|
|
404
|
+
else internalPatch((currentDraft) => deleteAtPath(currentDraft, path), meta);
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
returnValue = originalAction.apply(actionContextProxy, args);
|
|
409
|
+
};
|
|
410
|
+
internalPatch(recipe, meta);
|
|
411
|
+
draftActive = false;
|
|
412
|
+
return returnValue;
|
|
413
|
+
};
|
|
414
|
+
});
|
|
415
|
+
localScope.createStoreProxy = createStoreProxy;
|
|
416
|
+
pinia._p.forEach((plugin) => {
|
|
417
|
+
const pluginResult = plugin({
|
|
418
|
+
id,
|
|
419
|
+
store: storePublicApi,
|
|
420
|
+
options,
|
|
421
|
+
pinia,
|
|
422
|
+
restoreState
|
|
423
|
+
});
|
|
424
|
+
if (pluginResult) {
|
|
425
|
+
Object.defineProperties(proxyTarget, Object.getOwnPropertyDescriptors(pluginResult));
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
pinia._s.set(id, storePublicApi);
|
|
429
|
+
return storePublicApi;
|
|
430
|
+
}
|
|
431
|
+
function getStore() {
|
|
432
|
+
const pinia = getActivePinia();
|
|
433
|
+
ensureStoreInstance(pinia);
|
|
434
|
+
if (activeListenerId && activeGetterKey && activeListenerId !== id) {
|
|
435
|
+
const accessedStoreScope = pinia._scopes.get(id);
|
|
436
|
+
if (accessedStoreScope) {
|
|
437
|
+
let subscribers = accessedStoreScope.subscribers.get(activeListenerId);
|
|
438
|
+
if (!subscribers) {
|
|
439
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
440
|
+
accessedStoreScope.subscribers.set(activeListenerId, subscribers);
|
|
441
|
+
}
|
|
442
|
+
subscribers.add(activeGetterKey);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return pinia._s.get(id);
|
|
446
|
+
}
|
|
447
|
+
function useStore() {
|
|
448
|
+
const pinia = getActivePinia();
|
|
449
|
+
ensureStoreInstance(pinia);
|
|
450
|
+
const currentScope = pinia._scopes.get(id);
|
|
451
|
+
const trackedPaths = (0, import_react.useRef)(/* @__PURE__ */ new Set());
|
|
452
|
+
trackedPaths.current.clear();
|
|
453
|
+
const subscribe = (0, import_react.useCallback)(
|
|
454
|
+
(onStoreChange) => {
|
|
455
|
+
const listener = (_state, _prevState, patches) => {
|
|
456
|
+
let shouldUpdate = false;
|
|
457
|
+
for (const path of trackedPaths.current) {
|
|
458
|
+
if (path.length === 1 && path[0] === "$state") {
|
|
459
|
+
shouldUpdate = patches.length > 0;
|
|
460
|
+
if (shouldUpdate) break;
|
|
461
|
+
}
|
|
462
|
+
const topKey = path[0];
|
|
463
|
+
if (path.length === 1 && topKey in getters) {
|
|
464
|
+
if (!currentScope.getterResultCache.has(topKey)) {
|
|
465
|
+
shouldUpdate = true;
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
} else {
|
|
469
|
+
if (patches.length > 0 && isAffected(patches, /* @__PURE__ */ new Set([path]))) {
|
|
470
|
+
shouldUpdate = true;
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
if (shouldUpdate) {
|
|
476
|
+
onStoreChange();
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
currentScope.listeners.add(listener);
|
|
480
|
+
return () => currentScope.listeners.delete(listener);
|
|
481
|
+
},
|
|
482
|
+
[currentScope]
|
|
483
|
+
);
|
|
484
|
+
const getSnapshot = (0, import_react.useCallback)(() => currentScope.currentState, [currentScope]);
|
|
485
|
+
(0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
486
|
+
const trackingProxy = currentScope.createStoreProxy((path) => {
|
|
487
|
+
trackedPaths.current.add(path);
|
|
488
|
+
});
|
|
489
|
+
return trackingProxy;
|
|
490
|
+
}
|
|
491
|
+
const storeName = id.charAt(0).toUpperCase() + id.slice(1);
|
|
492
|
+
const definition = Object.assign(
|
|
493
|
+
{ useStore, getStore },
|
|
494
|
+
{
|
|
495
|
+
[`use${storeName}Store`]: useStore,
|
|
496
|
+
[`get${storeName}Store`]: getStore
|
|
497
|
+
}
|
|
498
|
+
);
|
|
499
|
+
return definition;
|
|
500
|
+
}
|
|
501
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
502
|
+
0 && (module.exports = {
|
|
503
|
+
createPinia,
|
|
504
|
+
defineStore,
|
|
505
|
+
getActivePinia,
|
|
506
|
+
setActivePinia
|
|
507
|
+
});
|
|
508
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/rootStore.ts","../src/createPinia.ts","../src/store.ts"],"sourcesContent":["export { createPinia } from './createPinia'\nexport { getActivePinia, setActivePinia } from './rootStore'\nexport { defineStore } from './store'\n\nexport type {\n DeepReadonly,\n DefineStoreOptions,\n DefineStoreOptionsBase,\n MutationEvent,\n MutationListener,\n MutationMeta,\n MutationType,\n Pinia,\n PiniaCustomProperties,\n PiniaPlugin,\n PiniaPluginContext,\n RestoreStateOptions,\n StatePath,\n StateTree,\n Store,\n StoreDefinition,\n StoreGeneric,\n SubscriptionCallback\n} from './types'\n","import type { Pinia } from './types'\n\nexport let activePinia: Pinia | undefined\n\nexport function setActivePinia(pinia: Pinia) {\n activePinia = pinia\n}\n\nexport function getActivePinia(): Pinia {\n if (!activePinia) {\n throw new Error(\n '[pinia-react] getActivePinia was called with no active Pinia. Did you forget to install pinia?\\n' +\n 'const pinia = createPinia() or createPinia() first.\\n'\n )\n }\n return activePinia\n}\n","import { setActivePinia } from './rootStore'\nimport type { MutationListener, Pinia, StateTree, StoreGeneric } from './types'\n\nexport function createPinia(): Pinia {\n const state: Record<string, StateTree> = {}\n const _p: Pinia['_p'] = []\n const _s = new Map<string, StoreGeneric>()\n const _scopes = new Map()\n const _m = new Set<MutationListener>()\n\n const pinia: Pinia = {\n use(plugin) {\n if (_s.size > 0) {\n console.warn(\n '[pinia-react] A plugin was registered after stores were created. ' +\n 'The new plugin will not be applied to the stores that already exist.'\n )\n }\n _p.push(plugin)\n return this\n },\n onMutation(listener) {\n _m.add(listener)\n return () => _m.delete(listener)\n },\n _p,\n _s,\n _scopes,\n _m,\n state\n }\n\n setActivePinia(pinia)\n\n return pinia\n}\n","import { type Draft, enablePatches, Immer, type Patch } from 'immer'\nimport { useCallback, useRef, useSyncExternalStore } from 'react'\nimport { getActivePinia } from './rootStore'\nimport type {\n DefineStoreOptions,\n MutationEvent,\n MutationMeta,\n Pinia,\n PiniaPluginContext,\n RestoreStateOptions,\n StatePath,\n StateTree,\n Store,\n StoreDefinitionWithNames,\n StoreScope,\n SubscriptionCallback,\n TransformActions\n} from './types'\n\nenablePatches()\n\n// Isolated Immer instance: keeps `autoFreeze: false` out of the host app's global Immer config.\nconst immer = new Immer({ autoFreeze: false })\n\nlet activeListenerId: string | null = null\nlet activeGetterKey: string | null = null\n\nconst storeDefinitionByPinia = new WeakMap<Pinia, Map<string, unknown>>()\n\nfunction isAffected(patches: Patch[], trackedPaths: Set<StatePath>): boolean {\n if (trackedPaths.size === 0) return false\n const tracked = Array.from(trackedPaths)\n\n for (const patch of patches) {\n const patchPath = patch.path.map(String)\n for (const trackedPath of tracked) {\n const len = Math.min(patchPath.length, trackedPath.length)\n let isPrefixMatch = true\n for (let i = 0; i < len; i++) {\n if (patchPath[i] !== trackedPath[i]) {\n isPrefixMatch = false\n break\n }\n }\n if (isPrefixMatch) return true\n }\n }\n return false\n}\n\n// Only plain objects and arrays are safe to wrap in a proxy; Date/Map/Set break their internal slots.\nfunction isPlainObjectOrArray(value: unknown): value is object {\n if (Array.isArray(value)) return true\n if (value === null || typeof value !== 'object') return false\n const proto = Object.getPrototypeOf(value)\n return proto === Object.prototype || proto === null\n}\n\nexport function defineStore<\n Id extends string,\n S extends StateTree,\n G extends Record<string, any> = {},\n A extends Record<string, any> = {}\n>(id: Id, options: DefineStoreOptions<S, G, A>): StoreDefinitionWithNames<Id, S, G, A> {\n const getters = options.getters || ({} as G)\n\n function ensureStoreInstance(pinia: Pinia) {\n if (pinia._s.has(id)) {\n if (storeDefinitionByPinia.get(pinia)?.get(id) === options) return\n console.warn(\n `[pinia-react] Duplicate store id \"${id}\" detected. The new definition replaces the previous store with the same id.`\n )\n }\n createStoreInstance()\n }\n\n function resolveGetterDependencies(\n getterName: string,\n getterDepsMap: Map<string, Set<StatePath>>,\n visited = new Set<string>()\n ): Set<StatePath> {\n if (visited.has(getterName)) {\n console.warn(`[pinia-react] Circular dependency in getters detected involving: ${getterName}`)\n return new Set()\n }\n visited.add(getterName)\n\n const finalDeps = new Set<StatePath>()\n const directDeps = getterDepsMap.get(getterName)\n\n if (!directDeps) return finalDeps\n\n for (const dep of directDeps) {\n const getterKey = dep.length === 1 ? dep[0] : undefined\n if (getterKey && getterKey in getters) {\n const nestedDeps = resolveGetterDependencies(getterKey, getterDepsMap, visited)\n nestedDeps.forEach((d) => finalDeps.add(d))\n } else {\n finalDeps.add(dep)\n }\n }\n return finalDeps\n }\n\n function createStoreInstance(): Store<Id, S, G, A> {\n const pinia = getActivePinia()\n const initialState = options.state()\n\n let storePublicApi: Store<Id, S, G, A>\n\n const localScope: StoreScope = {\n currentState: initialState,\n listeners: new Set(),\n getterResultCache: new Map(),\n getterDependencies: new Map(),\n subscribers: new Map(),\n createStoreProxy: (_onAccess?: (path: StatePath) => void) => storePublicApi as any\n }\n pinia._scopes.set(id, localScope)\n\n let definitionsById = storeDefinitionByPinia.get(pinia)\n if (!definitionsById) {\n definitionsById = new Map()\n storeDefinitionByPinia.set(pinia, definitionsById)\n }\n definitionsById.set(id, options)\n\n const isGetterComputing = new Set<string>()\n\n const emit = (nextState: S, oldState: S, patches: Patch[]) => {\n localScope.listeners.forEach((fn) => fn(nextState, oldState, patches))\n\n localScope.subscribers.forEach((getterKeys, storeId) => {\n const subscriberScope = pinia._scopes.get(storeId)\n if (!subscriberScope) return\n let shouldNotify = false\n getterKeys.forEach((key) => {\n if (subscriberScope.getterResultCache.has(key)) {\n subscriberScope.getterResultCache.delete(key)\n shouldNotify = true\n }\n })\n if (shouldNotify) {\n const oldSubState = subscriberScope.currentState\n const newSubState = { ...oldSubState }\n subscriberScope.currentState = newSubState\n pinia.state[storeId] = newSubState\n\n subscriberScope.listeners.forEach((fn) => fn(newSubState, oldSubState, []))\n }\n })\n }\n\n const internalPatch = (updater: (draft: Draft<S>) => void | S, meta: MutationMeta) => {\n const oldState = localScope.currentState as S\n let patches: Patch[] = []\n\n const nextState = immer.produce(oldState, updater as any, (p) => {\n patches = p\n }) as S\n\n if (patches.length > 0 || meta.type === 'reset') {\n localScope.currentState = nextState\n pinia.state[id] = nextState\n emit(nextState, oldState, patches)\n const event: MutationEvent<S> = {\n storeId: id,\n store: storePublicApi as any,\n state: nextState,\n prevState: oldState,\n patches,\n meta\n }\n pinia._m.forEach((listener) => listener(event))\n }\n }\n\n const $patch = (updater: (draft: Draft<S>) => void) => {\n internalPatch(\n (draft) => {\n updater(draft)\n },\n { type: 'patch' }\n )\n }\n\n const $reset = () => internalPatch(() => options.state(), { type: 'reset' })\n\n const restoreState = (state: S, options: RestoreStateOptions = {}) => {\n internalPatch(() => state, {\n type: options.type ?? 'restore',\n origin: options.origin\n })\n }\n\n const $subscribe = (callback: SubscriptionCallback<S>) => {\n const listener = (state: S, prev: S) => callback(state, prev)\n localScope.listeners.add(listener as any)\n return () => localScope.listeners.delete(listener as any)\n }\n\n const getterInvalidationListener = (_state: S, _prevState: S, patches: Patch[]) => {\n localScope.getterDependencies.forEach((_deps, getterName) => {\n const resolvedDeps = resolveGetterDependencies(getterName, localScope.getterDependencies)\n if (isAffected(patches, resolvedDeps)) {\n localScope.getterResultCache.delete(getterName)\n }\n })\n }\n localScope.listeners.add(getterInvalidationListener as any)\n\n const originalActions = options.actions || ({} as A)\n const wrappedActions = {} as TransformActions<A>\n const proxyTarget = {}\n const readonlyStateProxyCache = new WeakMap<object, object>()\n\n const readonlyWarning = () => {\n console.warn(`[${id}] Store is read-only. Use actions for mutations.`)\n throw new TypeError(`[${id}] Store is read-only. Use actions for mutations.`)\n }\n\n const createReadonlyStateProxy = (stateTarget: any): any => {\n const cached = readonlyStateProxyCache.get(stateTarget)\n if (cached) return cached\n\n const proxy = new Proxy(stateTarget, {\n get(obj, key) {\n const value = Reflect.get(obj, key)\n if (isPlainObjectOrArray(value)) return createReadonlyStateProxy(value)\n return value\n },\n set: readonlyWarning,\n deleteProperty: readonlyWarning\n })\n readonlyStateProxyCache.set(stateTarget, proxy)\n return proxy\n }\n\n const getAtPath = (path: StatePath) => {\n let value: any = localScope.currentState\n for (const key of path) value = value[key]\n return value\n }\n\n const setAtPath = (draft: Draft<S>, path: StatePath, value: unknown) => {\n let target: any = draft\n for (let i = 0; i < path.length - 1; i++) target = target[path[i]]\n target[path[path.length - 1]] = value\n }\n\n const deleteAtPath = (draft: Draft<S>, path: StatePath) => {\n let target: any = draft\n for (let i = 0; i < path.length - 1; i++) target = target[path[i]]\n delete target[path[path.length - 1]]\n }\n\n const createActionStateProxy = (path: StatePath, meta: MutationMeta): any => {\n return new Proxy(Array.isArray(getAtPath(path)) ? [] : {}, {\n get(_target, key, receiver) {\n const current = getAtPath(path)\n const value = Reflect.get(current, key, receiver)\n if (typeof key === 'symbol' || !isPlainObjectOrArray(value)) return value\n return createActionStateProxy([...path, String(key)], meta)\n },\n set(_target, key, value) {\n internalPatch((draft) => setAtPath(draft, [...path, String(key)], value), meta)\n return true\n },\n deleteProperty(_target, key) {\n internalPatch((draft) => deleteAtPath(draft, [...path, String(key)]), meta)\n return true\n }\n })\n }\n\n function createStoreProxy(onAccess?: (path: StatePath) => void): Store<Id, S, G, A> {\n const createStateProxy = (\n stateTarget: any,\n path: StatePath,\n onDeepAccess?: (path: StatePath) => void,\n trackObjectAccess = false\n ): any => {\n return new Proxy(stateTarget, {\n get(obj, key) {\n if (typeof key === 'symbol') return Reflect.get(obj, key)\n const currentPath = [...path, String(key)]\n const value = Reflect.get(obj, key)\n if (isPlainObjectOrArray(value)) {\n if (trackObjectAccess) onDeepAccess?.(currentPath)\n return createStateProxy(value, currentPath, onDeepAccess, trackObjectAccess)\n }\n onDeepAccess?.(currentPath)\n return value\n },\n set: readonlyWarning,\n deleteProperty: readonlyWarning\n })\n }\n\n return new Proxy(proxyTarget as any, {\n get(_target, key, receiver) {\n const strKey = String(key)\n\n if (strKey === '$state') {\n onAccess?.(['$state'])\n return createReadonlyStateProxy(localScope.currentState)\n }\n if (strKey === '$id') return id\n if (strKey === '$patch') return $patch\n if (strKey === '$reset') return $reset\n if (strKey === '$subscribe') return $subscribe\n\n const state = localScope.currentState\n if (strKey in state) {\n const value = state[strKey]\n if (isPlainObjectOrArray(value)) {\n return createStateProxy(value, [strKey], onAccess)\n }\n onAccess?.([strKey])\n return value\n }\n\n if (strKey in getters) {\n onAccess?.([strKey])\n if (localScope.getterResultCache.has(strKey)) return localScope.getterResultCache.get(strKey)\n if (isGetterComputing.has(strKey)) {\n console.warn(`[pinia-react] Circular dependency detected in getter \"${strKey}\"`)\n return undefined\n }\n\n isGetterComputing.add(strKey)\n const dependencies = new Set<StatePath>()\n const prevListenerId = activeListenerId\n const prevGetterKey = activeGetterKey\n activeListenerId = id\n activeGetterKey = strKey\n\n try {\n const onGetterAccess = (path: StatePath) => {\n dependencies.add(path)\n }\n const trackingProxyForThis = createStoreProxy(onGetterAccess)\n const trackingStateProxy = createStateProxy(state, [], onGetterAccess, true)\n const result = (getters as any)[strKey].call(trackingProxyForThis, trackingStateProxy)\n\n localScope.getterDependencies.set(strKey, dependencies)\n localScope.getterResultCache.set(strKey, result)\n return result\n } finally {\n activeListenerId = prevListenerId\n activeGetterKey = prevGetterKey\n isGetterComputing.delete(strKey)\n }\n }\n\n if (strKey in wrappedActions) {\n return (wrappedActions as any)[strKey]\n }\n\n return Reflect.get(_target, key, receiver)\n },\n set(_target, key, value, receiver) {\n const strKey = String(key)\n if (strKey === '$state') {\n console.warn(`[${id}] Do not replace \"$state\" directly. Use \"$patch()\" to replace the whole state.`)\n return false\n }\n if (strKey === '$id') return readonlyWarning()\n if (strKey in localScope.currentState || strKey in getters || strKey in wrappedActions) {\n return readonlyWarning()\n }\n return Reflect.set(_target, key, value, receiver)\n }\n }) as Store<Id, S, G, A>\n }\n\n storePublicApi = createStoreProxy()\n\n Object.keys(originalActions).forEach((actionName) => {\n const originalAction = (originalActions as any)[actionName]\n ;(wrappedActions as any)[actionName] = (...args: any[]) => {\n let returnValue: any\n let draftActive = true\n const meta: MutationMeta = { type: 'action', action: actionName, args }\n const recipe = (draft: Draft<S>) => {\n const actionContextProxy = new Proxy({} as any, {\n get(_, key) {\n const strKey = String(key)\n if (draftActive && Reflect.has(draft, strKey)) return (draft as any)[strKey]\n if (!draftActive && Reflect.has(localScope.currentState, strKey)) {\n const value = (localScope.currentState as any)[strKey]\n if (value !== null && typeof value === 'object') return createActionStateProxy([strKey], meta)\n return value\n }\n if (strKey in getters) {\n if (draftActive) return (getters as any)[strKey].call(actionContextProxy, draft)\n return Reflect.get(storePublicApi, key, storePublicApi)\n }\n return Reflect.get(storePublicApi, key, storePublicApi)\n },\n set(_, key, value) {\n const path = [String(key)]\n if (draftActive) (draft as any)[path[0]] = value\n else internalPatch((currentDraft) => setAtPath(currentDraft, path, value), meta)\n return true\n },\n deleteProperty(_, key) {\n const path = [String(key)]\n if (draftActive) delete (draft as any)[path[0]]\n else internalPatch((currentDraft) => deleteAtPath(currentDraft, path), meta)\n return true\n }\n })\n returnValue = originalAction.apply(actionContextProxy, args)\n }\n internalPatch(recipe, meta)\n draftActive = false\n return returnValue\n }\n })\n\n localScope.createStoreProxy = createStoreProxy as any\n\n pinia._p.forEach((plugin) => {\n const pluginResult = plugin({\n id,\n store: storePublicApi,\n options,\n pinia,\n restoreState\n } as PiniaPluginContext)\n if (pluginResult) {\n Object.defineProperties(proxyTarget, Object.getOwnPropertyDescriptors(pluginResult))\n }\n })\n\n pinia._s.set(id, storePublicApi as any)\n\n return storePublicApi\n }\n\n function getStore(): Store<Id, S, G, A> {\n const pinia = getActivePinia()\n ensureStoreInstance(pinia)\n\n if (activeListenerId && activeGetterKey && activeListenerId !== id) {\n const accessedStoreScope = pinia._scopes.get(id)\n if (accessedStoreScope) {\n let subscribers = accessedStoreScope.subscribers.get(activeListenerId)\n if (!subscribers) {\n subscribers = new Set()\n accessedStoreScope.subscribers.set(activeListenerId, subscribers)\n }\n subscribers.add(activeGetterKey)\n }\n }\n\n return pinia._s.get(id) as Store<Id, S, G, A>\n }\n\n function useStore(): Store<Id, S, G, A> {\n const pinia = getActivePinia()\n ensureStoreInstance(pinia)\n const currentScope = pinia._scopes.get(id)!\n\n const trackedPaths = useRef(new Set<StatePath>())\n trackedPaths.current.clear()\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n const listener = (_state: S, _prevState: S, patches: Patch[]) => {\n let shouldUpdate = false\n for (const path of trackedPaths.current) {\n if (path.length === 1 && path[0] === '$state') {\n shouldUpdate = patches.length > 0\n if (shouldUpdate) break\n }\n const topKey = path[0]\n if (path.length === 1 && topKey in getters) {\n if (!currentScope.getterResultCache.has(topKey)) {\n shouldUpdate = true\n break\n }\n } else {\n if (patches.length > 0 && isAffected(patches, new Set([path]))) {\n shouldUpdate = true\n break\n }\n }\n }\n if (shouldUpdate) {\n onStoreChange()\n }\n }\n currentScope.listeners.add(listener as any)\n return () => currentScope.listeners.delete(listener as any)\n },\n [currentScope]\n )\n\n const getSnapshot = useCallback(() => currentScope.currentState, [currentScope])\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n\n const trackingProxy = currentScope.createStoreProxy((path) => {\n trackedPaths.current.add(path)\n })\n\n return trackingProxy as Store<Id, S, G, A>\n }\n\n const storeName = (id.charAt(0).toUpperCase() + id.slice(1)) as Capitalize<Id>\n\n const definition: StoreDefinitionWithNames<Id, S, G, A> = Object.assign(\n { useStore, getStore },\n {\n [`use${storeName}Store`]: useStore,\n [`get${storeName}Store`]: getStore\n }\n ) as unknown as StoreDefinitionWithNames<Id, S, G, A>\n\n return definition\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAI;AAEJ,SAAS,eAAe,OAAc;AAC3C,gBAAc;AAChB;AAEO,SAAS,iBAAwB;AACtC,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,SAAO;AACT;;;ACbO,SAAS,cAAqB;AACnC,QAAM,QAAmC,CAAC;AAC1C,QAAM,KAAkB,CAAC;AACzB,QAAM,KAAK,oBAAI,IAA0B;AACzC,QAAM,UAAU,oBAAI,IAAI;AACxB,QAAM,KAAK,oBAAI,IAAsB;AAErC,QAAM,QAAe;AAAA,IACnB,IAAI,QAAQ;AACV,UAAI,GAAG,OAAO,GAAG;AACf,gBAAQ;AAAA,UACN;AAAA,QAEF;AAAA,MACF;AACA,SAAG,KAAK,MAAM;AACd,aAAO;AAAA,IACT;AAAA,IACA,WAAW,UAAU;AACnB,SAAG,IAAI,QAAQ;AACf,aAAO,MAAM,GAAG,OAAO,QAA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SAAS,OAAO,GAAG;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;","names":["options"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Draft, Patch } from 'immer';
|
|
2
|
+
|
|
3
|
+
type StateTree = Record<string, any>;
|
|
4
|
+
type StatePath = string[];
|
|
5
|
+
type MutationType = 'action' | 'patch' | 'reset' | 'restore';
|
|
6
|
+
/** Metadata describing why a state transition was committed. */
|
|
7
|
+
interface MutationMeta {
|
|
8
|
+
type: MutationType;
|
|
9
|
+
origin?: string;
|
|
10
|
+
action?: string;
|
|
11
|
+
args?: unknown[];
|
|
12
|
+
}
|
|
13
|
+
/** A committed state transition, intended for Pinia plugins. */
|
|
14
|
+
interface MutationEvent<S extends StateTree = StateTree> {
|
|
15
|
+
storeId: string;
|
|
16
|
+
store: StoreGeneric;
|
|
17
|
+
state: S;
|
|
18
|
+
prevState: S;
|
|
19
|
+
patches: Patch[];
|
|
20
|
+
meta: MutationMeta;
|
|
21
|
+
}
|
|
22
|
+
type MutationListener = (event: MutationEvent) => void;
|
|
23
|
+
interface RestoreStateOptions {
|
|
24
|
+
type?: Extract<MutationType, 'restore' | 'reset'>;
|
|
25
|
+
origin?: string;
|
|
26
|
+
}
|
|
27
|
+
type TransformGetters<G> = {
|
|
28
|
+
[K in keyof G]: G[K] extends (...args: any[]) => infer R ? R : never;
|
|
29
|
+
};
|
|
30
|
+
type TransformActions<A> = A;
|
|
31
|
+
type SubscriptionCallback<S> = (state: S, prevState: S) => void;
|
|
32
|
+
type DeepReadonly<T> = T extends (...args: any[]) => any ? T : T extends readonly (infer U)[] ? ReadonlyArray<DeepReadonly<U>> : T extends object ? {
|
|
33
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
34
|
+
} : T;
|
|
35
|
+
interface PiniaCustomProperties<Id extends string = string, S extends StateTree = StateTree, G extends Record<string, any> = Record<string, any>, A extends Record<string, any> = Record<string, any>> {
|
|
36
|
+
}
|
|
37
|
+
interface StorePublicApi<Id extends string = string, S = StateTree> {
|
|
38
|
+
readonly $id: Id;
|
|
39
|
+
$patch: (updater: (draft: Draft<S>) => void) => void;
|
|
40
|
+
$reset: () => void;
|
|
41
|
+
$subscribe: (callback: SubscriptionCallback<S>) => () => void;
|
|
42
|
+
$state: DeepReadonly<S>;
|
|
43
|
+
}
|
|
44
|
+
type GetterContext<S, G> = Readonly<S> & TransformGetters<G>;
|
|
45
|
+
type ActionContext<S, G, A> = S & TransformGetters<G> & TransformActions<A> & StorePublicApi<string, S>;
|
|
46
|
+
type Store<Id extends string, S extends StateTree, G extends Record<string, any>, A extends Record<string, any>> = S & TransformGetters<G> & TransformActions<A> & StorePublicApi<Id, S> & PiniaCustomProperties<Id, S, G, A>;
|
|
47
|
+
type StoreGeneric = Store<string, StateTree, Record<string, any>, Record<string, any>>;
|
|
48
|
+
type GettersImplementation<S> = {
|
|
49
|
+
[K in string]: (state: S) => any;
|
|
50
|
+
};
|
|
51
|
+
/** Extension point for store-option plugins. */
|
|
52
|
+
interface DefineStoreOptionsBase<S extends StateTree, Store> {
|
|
53
|
+
}
|
|
54
|
+
interface DefineStoreOptions<S extends StateTree, G extends Record<string, any>, A extends Record<string, any>> extends DefineStoreOptionsBase<S, Store<string, S, G, A>> {
|
|
55
|
+
state: () => S;
|
|
56
|
+
getters?: G & ThisType<GetterContext<S, G>> & GettersImplementation<S>;
|
|
57
|
+
actions?: A & ThisType<ActionContext<S, G, A>>;
|
|
58
|
+
}
|
|
59
|
+
type StoreScope = {
|
|
60
|
+
currentState: StateTree;
|
|
61
|
+
listeners: Set<(state: any, prev: any, patches: Patch[]) => void>;
|
|
62
|
+
getterResultCache: Map<string, any>;
|
|
63
|
+
getterDependencies: Map<string, Set<StatePath>>;
|
|
64
|
+
subscribers: Map<string, Set<string>>;
|
|
65
|
+
createStoreProxy: (onAccess?: (path: StatePath) => void) => StoreGeneric;
|
|
66
|
+
};
|
|
67
|
+
interface Pinia {
|
|
68
|
+
state: Record<string, StateTree>;
|
|
69
|
+
use(plugin: PiniaPlugin): Pinia;
|
|
70
|
+
/** Subscribe to committed mutations from every store in this Pinia instance. */
|
|
71
|
+
onMutation(listener: MutationListener): () => void;
|
|
72
|
+
_p: PiniaPlugin[];
|
|
73
|
+
_s: Map<string, StoreGeneric>;
|
|
74
|
+
_scopes: Map<string, StoreScope>;
|
|
75
|
+
_m: Set<MutationListener>;
|
|
76
|
+
}
|
|
77
|
+
interface PiniaPlugin {
|
|
78
|
+
(context: PiniaPluginContext): Partial<PiniaCustomProperties> | void;
|
|
79
|
+
}
|
|
80
|
+
type PiniaPluginContext<Id extends string = string, S extends StateTree = StateTree, G extends Record<string, any> = Record<string, any>, A extends Record<string, any> = Record<string, any>> = {
|
|
81
|
+
id: Id;
|
|
82
|
+
store: Store<Id, S, G, A>;
|
|
83
|
+
options: DefineStoreOptions<S, G, A>;
|
|
84
|
+
pinia: Pinia;
|
|
85
|
+
/** A plugin-only, fully controlled state replacement operation. */
|
|
86
|
+
restoreState: (state: S, options?: RestoreStateOptions) => void;
|
|
87
|
+
};
|
|
88
|
+
interface StoreDefinition<Id extends string, S extends StateTree, G extends Record<string, any>, A extends Record<string, any>> {
|
|
89
|
+
useStore: () => Store<Id, S, G, A>;
|
|
90
|
+
getStore: () => Store<Id, S, G, A>;
|
|
91
|
+
}
|
|
92
|
+
type NamedStoreDefinition<Id extends string, S extends StateTree, G extends Record<string, any>, A extends Record<string, any>> = string extends Id ? {} : {
|
|
93
|
+
[K in `use${Capitalize<Id>}Store`]: () => Store<Id, S, G, A>;
|
|
94
|
+
} & {
|
|
95
|
+
[K in `get${Capitalize<Id>}Store`]: () => Store<Id, S, G, A>;
|
|
96
|
+
};
|
|
97
|
+
type StoreDefinitionWithNames<Id extends string, S extends StateTree, G extends Record<string, any>, A extends Record<string, any>> = StoreDefinition<Id, S, G, A> & NamedStoreDefinition<Id, S, G, A>;
|
|
98
|
+
|
|
99
|
+
declare function createPinia(): Pinia;
|
|
100
|
+
|
|
101
|
+
declare function setActivePinia(pinia: Pinia): void;
|
|
102
|
+
declare function getActivePinia(): Pinia;
|
|
103
|
+
|
|
104
|
+
declare function defineStore<Id extends string, S extends StateTree, G extends Record<string, any> = {}, A extends Record<string, any> = {}>(id: Id, options: DefineStoreOptions<S, G, A>): StoreDefinitionWithNames<Id, S, G, A>;
|
|
105
|
+
|
|
106
|
+
export { type DeepReadonly, type DefineStoreOptions, type DefineStoreOptionsBase, type MutationEvent, type MutationListener, type MutationMeta, type MutationType, type Pinia, type PiniaCustomProperties, type PiniaPlugin, type PiniaPluginContext, type RestoreStateOptions, type StatePath, type StateTree, type Store, type StoreDefinition, type StoreGeneric, type SubscriptionCallback, createPinia, defineStore, getActivePinia, setActivePinia };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Draft, Patch } from 'immer';
|
|
2
2
|
|
|
3
3
|
type StateTree = Record<string, any>;
|
|
4
|
+
type StatePath = string[];
|
|
4
5
|
type MutationType = 'action' | 'patch' | 'reset' | 'restore';
|
|
5
6
|
/** Metadata describing why a state transition was committed. */
|
|
6
7
|
interface MutationMeta {
|
|
@@ -28,17 +29,21 @@ type TransformGetters<G> = {
|
|
|
28
29
|
};
|
|
29
30
|
type TransformActions<A> = A;
|
|
30
31
|
type SubscriptionCallback<S> = (state: S, prevState: S) => void;
|
|
32
|
+
type DeepReadonly<T> = T extends (...args: any[]) => any ? T : T extends readonly (infer U)[] ? ReadonlyArray<DeepReadonly<U>> : T extends object ? {
|
|
33
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
34
|
+
} : T;
|
|
31
35
|
interface PiniaCustomProperties<Id extends string = string, S extends StateTree = StateTree, G extends Record<string, any> = Record<string, any>, A extends Record<string, any> = Record<string, any>> {
|
|
32
36
|
}
|
|
33
|
-
interface StorePublicApi<S> {
|
|
37
|
+
interface StorePublicApi<Id extends string = string, S = StateTree> {
|
|
38
|
+
readonly $id: Id;
|
|
34
39
|
$patch: (updater: (draft: Draft<S>) => void) => void;
|
|
35
40
|
$reset: () => void;
|
|
36
41
|
$subscribe: (callback: SubscriptionCallback<S>) => () => void;
|
|
37
|
-
$state: S
|
|
42
|
+
$state: DeepReadonly<S>;
|
|
38
43
|
}
|
|
39
44
|
type GetterContext<S, G> = Readonly<S> & TransformGetters<G>;
|
|
40
|
-
type ActionContext<S, G, A> = S & TransformGetters<G> & TransformActions<A> & StorePublicApi<S>;
|
|
41
|
-
type Store<Id extends string, S extends StateTree, G extends Record<string, any>, A extends Record<string, any>> = S & TransformGetters<G> & TransformActions<A> & StorePublicApi<S> & PiniaCustomProperties<Id, S, G, A>;
|
|
45
|
+
type ActionContext<S, G, A> = S & TransformGetters<G> & TransformActions<A> & StorePublicApi<string, S>;
|
|
46
|
+
type Store<Id extends string, S extends StateTree, G extends Record<string, any>, A extends Record<string, any>> = S & TransformGetters<G> & TransformActions<A> & StorePublicApi<Id, S> & PiniaCustomProperties<Id, S, G, A>;
|
|
42
47
|
type StoreGeneric = Store<string, StateTree, Record<string, any>, Record<string, any>>;
|
|
43
48
|
type GettersImplementation<S> = {
|
|
44
49
|
[K in string]: (state: S) => any;
|
|
@@ -55,9 +60,9 @@ type StoreScope = {
|
|
|
55
60
|
currentState: StateTree;
|
|
56
61
|
listeners: Set<(state: any, prev: any, patches: Patch[]) => void>;
|
|
57
62
|
getterResultCache: Map<string, any>;
|
|
58
|
-
getterDependencies: Map<string, Set<
|
|
63
|
+
getterDependencies: Map<string, Set<StatePath>>;
|
|
59
64
|
subscribers: Map<string, Set<string>>;
|
|
60
|
-
createStoreProxy: (onAccess?: (path:
|
|
65
|
+
createStoreProxy: (onAccess?: (path: StatePath) => void) => StoreGeneric;
|
|
61
66
|
};
|
|
62
67
|
interface Pinia {
|
|
63
68
|
state: Record<string, StateTree>;
|
|
@@ -98,4 +103,4 @@ declare function getActivePinia(): Pinia;
|
|
|
98
103
|
|
|
99
104
|
declare function defineStore<Id extends string, S extends StateTree, G extends Record<string, any> = {}, A extends Record<string, any> = {}>(id: Id, options: DefineStoreOptions<S, G, A>): StoreDefinitionWithNames<Id, S, G, A>;
|
|
100
105
|
|
|
101
|
-
export { type DefineStoreOptions, type DefineStoreOptionsBase, type MutationEvent, type MutationListener, type MutationMeta, type MutationType, type Pinia, type PiniaCustomProperties, type PiniaPlugin, type PiniaPluginContext, type RestoreStateOptions, type StateTree, type Store, type StoreDefinition, type StoreGeneric, type SubscriptionCallback, createPinia, defineStore, getActivePinia, setActivePinia };
|
|
106
|
+
export { type DeepReadonly, type DefineStoreOptions, type DefineStoreOptionsBase, type MutationEvent, type MutationListener, type MutationMeta, type MutationType, type Pinia, type PiniaCustomProperties, type PiniaPlugin, type PiniaPluginContext, type RestoreStateOptions, type StatePath, type StateTree, type Store, type StoreDefinition, type StoreGeneric, type SubscriptionCallback, createPinia, defineStore, getActivePinia, setActivePinia };
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,11 @@ function createPinia() {
|
|
|
21
21
|
const _m = /* @__PURE__ */ new Set();
|
|
22
22
|
const pinia = {
|
|
23
23
|
use(plugin) {
|
|
24
|
+
if (_s.size > 0) {
|
|
25
|
+
console.warn(
|
|
26
|
+
"[pinia-react] A plugin was registered after stores were created. The new plugin will not be applied to the stores that already exist."
|
|
27
|
+
);
|
|
28
|
+
}
|
|
24
29
|
_p.push(plugin);
|
|
25
30
|
return this;
|
|
26
31
|
},
|
|
@@ -39,15 +44,16 @@ function createPinia() {
|
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
// src/store.ts
|
|
42
|
-
import { enablePatches,
|
|
47
|
+
import { enablePatches, Immer } from "immer";
|
|
43
48
|
import { useCallback, useRef, useSyncExternalStore } from "react";
|
|
44
49
|
enablePatches();
|
|
45
|
-
|
|
50
|
+
var immer = new Immer({ autoFreeze: false });
|
|
46
51
|
var activeListenerId = null;
|
|
47
52
|
var activeGetterKey = null;
|
|
53
|
+
var storeDefinitionByPinia = /* @__PURE__ */ new WeakMap();
|
|
48
54
|
function isAffected(patches, trackedPaths) {
|
|
49
55
|
if (trackedPaths.size === 0) return false;
|
|
50
|
-
const tracked = Array.from(trackedPaths)
|
|
56
|
+
const tracked = Array.from(trackedPaths);
|
|
51
57
|
for (const patch of patches) {
|
|
52
58
|
const patchPath = patch.path.map(String);
|
|
53
59
|
for (const trackedPath of tracked) {
|
|
@@ -64,8 +70,23 @@ function isAffected(patches, trackedPaths) {
|
|
|
64
70
|
}
|
|
65
71
|
return false;
|
|
66
72
|
}
|
|
73
|
+
function isPlainObjectOrArray(value) {
|
|
74
|
+
if (Array.isArray(value)) return true;
|
|
75
|
+
if (value === null || typeof value !== "object") return false;
|
|
76
|
+
const proto = Object.getPrototypeOf(value);
|
|
77
|
+
return proto === Object.prototype || proto === null;
|
|
78
|
+
}
|
|
67
79
|
function defineStore(id, options) {
|
|
68
80
|
const getters = options.getters || {};
|
|
81
|
+
function ensureStoreInstance(pinia) {
|
|
82
|
+
if (pinia._s.has(id)) {
|
|
83
|
+
if (storeDefinitionByPinia.get(pinia)?.get(id) === options) return;
|
|
84
|
+
console.warn(
|
|
85
|
+
`[pinia-react] Duplicate store id "${id}" detected. The new definition replaces the previous store with the same id.`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
createStoreInstance();
|
|
89
|
+
}
|
|
69
90
|
function resolveGetterDependencies(getterName, getterDepsMap, visited = /* @__PURE__ */ new Set()) {
|
|
70
91
|
if (visited.has(getterName)) {
|
|
71
92
|
console.warn(`[pinia-react] Circular dependency in getters detected involving: ${getterName}`);
|
|
@@ -76,8 +97,9 @@ function defineStore(id, options) {
|
|
|
76
97
|
const directDeps = getterDepsMap.get(getterName);
|
|
77
98
|
if (!directDeps) return finalDeps;
|
|
78
99
|
for (const dep of directDeps) {
|
|
79
|
-
|
|
80
|
-
|
|
100
|
+
const getterKey = dep.length === 1 ? dep[0] : void 0;
|
|
101
|
+
if (getterKey && getterKey in getters) {
|
|
102
|
+
const nestedDeps = resolveGetterDependencies(getterKey, getterDepsMap, visited);
|
|
81
103
|
nestedDeps.forEach((d) => finalDeps.add(d));
|
|
82
104
|
} else {
|
|
83
105
|
finalDeps.add(dep);
|
|
@@ -98,6 +120,12 @@ function defineStore(id, options) {
|
|
|
98
120
|
createStoreProxy: (_onAccess) => storePublicApi
|
|
99
121
|
};
|
|
100
122
|
pinia._scopes.set(id, localScope);
|
|
123
|
+
let definitionsById = storeDefinitionByPinia.get(pinia);
|
|
124
|
+
if (!definitionsById) {
|
|
125
|
+
definitionsById = /* @__PURE__ */ new Map();
|
|
126
|
+
storeDefinitionByPinia.set(pinia, definitionsById);
|
|
127
|
+
}
|
|
128
|
+
definitionsById.set(id, options);
|
|
101
129
|
const isGetterComputing = /* @__PURE__ */ new Set();
|
|
102
130
|
const emit = (nextState, oldState, patches) => {
|
|
103
131
|
localScope.listeners.forEach((fn) => fn(nextState, oldState, patches));
|
|
@@ -123,7 +151,7 @@ function defineStore(id, options) {
|
|
|
123
151
|
const internalPatch = (updater, meta) => {
|
|
124
152
|
const oldState = localScope.currentState;
|
|
125
153
|
let patches = [];
|
|
126
|
-
const nextState = produce(oldState, updater, (p) => {
|
|
154
|
+
const nextState = immer.produce(oldState, updater, (p) => {
|
|
127
155
|
patches = p;
|
|
128
156
|
});
|
|
129
157
|
if (patches.length > 0 || meta.type === "reset") {
|
|
@@ -173,37 +201,92 @@ function defineStore(id, options) {
|
|
|
173
201
|
const originalActions = options.actions || {};
|
|
174
202
|
const wrappedActions = {};
|
|
175
203
|
const proxyTarget = {};
|
|
204
|
+
const readonlyStateProxyCache = /* @__PURE__ */ new WeakMap();
|
|
205
|
+
const readonlyWarning = () => {
|
|
206
|
+
console.warn(`[${id}] Store is read-only. Use actions for mutations.`);
|
|
207
|
+
throw new TypeError(`[${id}] Store is read-only. Use actions for mutations.`);
|
|
208
|
+
};
|
|
209
|
+
const createReadonlyStateProxy = (stateTarget) => {
|
|
210
|
+
const cached = readonlyStateProxyCache.get(stateTarget);
|
|
211
|
+
if (cached) return cached;
|
|
212
|
+
const proxy = new Proxy(stateTarget, {
|
|
213
|
+
get(obj, key) {
|
|
214
|
+
const value = Reflect.get(obj, key);
|
|
215
|
+
if (isPlainObjectOrArray(value)) return createReadonlyStateProxy(value);
|
|
216
|
+
return value;
|
|
217
|
+
},
|
|
218
|
+
set: readonlyWarning,
|
|
219
|
+
deleteProperty: readonlyWarning
|
|
220
|
+
});
|
|
221
|
+
readonlyStateProxyCache.set(stateTarget, proxy);
|
|
222
|
+
return proxy;
|
|
223
|
+
};
|
|
224
|
+
const getAtPath = (path) => {
|
|
225
|
+
let value = localScope.currentState;
|
|
226
|
+
for (const key of path) value = value[key];
|
|
227
|
+
return value;
|
|
228
|
+
};
|
|
229
|
+
const setAtPath = (draft, path, value) => {
|
|
230
|
+
let target = draft;
|
|
231
|
+
for (let i = 0; i < path.length - 1; i++) target = target[path[i]];
|
|
232
|
+
target[path[path.length - 1]] = value;
|
|
233
|
+
};
|
|
234
|
+
const deleteAtPath = (draft, path) => {
|
|
235
|
+
let target = draft;
|
|
236
|
+
for (let i = 0; i < path.length - 1; i++) target = target[path[i]];
|
|
237
|
+
delete target[path[path.length - 1]];
|
|
238
|
+
};
|
|
239
|
+
const createActionStateProxy = (path, meta) => {
|
|
240
|
+
return new Proxy(Array.isArray(getAtPath(path)) ? [] : {}, {
|
|
241
|
+
get(_target, key, receiver) {
|
|
242
|
+
const current = getAtPath(path);
|
|
243
|
+
const value = Reflect.get(current, key, receiver);
|
|
244
|
+
if (typeof key === "symbol" || !isPlainObjectOrArray(value)) return value;
|
|
245
|
+
return createActionStateProxy([...path, String(key)], meta);
|
|
246
|
+
},
|
|
247
|
+
set(_target, key, value) {
|
|
248
|
+
internalPatch((draft) => setAtPath(draft, [...path, String(key)], value), meta);
|
|
249
|
+
return true;
|
|
250
|
+
},
|
|
251
|
+
deleteProperty(_target, key) {
|
|
252
|
+
internalPatch((draft) => deleteAtPath(draft, [...path, String(key)]), meta);
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
};
|
|
176
257
|
function createStoreProxy(onAccess) {
|
|
177
|
-
const
|
|
178
|
-
console.warn(`[${id}] Store is read-only. Use actions for mutations.`);
|
|
179
|
-
return false;
|
|
180
|
-
};
|
|
181
|
-
const createStateProxy = (stateTarget, path, onDeepAccess) => {
|
|
258
|
+
const createStateProxy = (stateTarget, path, onDeepAccess, trackObjectAccess = false) => {
|
|
182
259
|
return new Proxy(stateTarget, {
|
|
183
260
|
get(obj, key) {
|
|
184
261
|
if (typeof key === "symbol") return Reflect.get(obj, key);
|
|
185
262
|
const currentPath = [...path, String(key)];
|
|
186
263
|
const value = Reflect.get(obj, key);
|
|
187
|
-
if (
|
|
188
|
-
|
|
264
|
+
if (isPlainObjectOrArray(value)) {
|
|
265
|
+
if (trackObjectAccess) onDeepAccess?.(currentPath);
|
|
266
|
+
return createStateProxy(value, currentPath, onDeepAccess, trackObjectAccess);
|
|
189
267
|
}
|
|
190
268
|
onDeepAccess?.(currentPath);
|
|
191
269
|
return value;
|
|
192
270
|
},
|
|
193
|
-
set: readonlyWarning
|
|
271
|
+
set: readonlyWarning,
|
|
272
|
+
deleteProperty: readonlyWarning
|
|
194
273
|
});
|
|
195
274
|
};
|
|
196
275
|
return new Proxy(proxyTarget, {
|
|
197
276
|
get(_target, key, receiver) {
|
|
198
277
|
const strKey = String(key);
|
|
199
|
-
if (strKey === "$state")
|
|
278
|
+
if (strKey === "$state") {
|
|
279
|
+
onAccess?.(["$state"]);
|
|
280
|
+
return createReadonlyStateProxy(localScope.currentState);
|
|
281
|
+
}
|
|
282
|
+
if (strKey === "$id") return id;
|
|
200
283
|
if (strKey === "$patch") return $patch;
|
|
201
284
|
if (strKey === "$reset") return $reset;
|
|
202
285
|
if (strKey === "$subscribe") return $subscribe;
|
|
203
286
|
const state = localScope.currentState;
|
|
204
287
|
if (strKey in state) {
|
|
205
288
|
const value = state[strKey];
|
|
206
|
-
if (
|
|
289
|
+
if (isPlainObjectOrArray(value)) {
|
|
207
290
|
return createStateProxy(value, [strKey], onAccess);
|
|
208
291
|
}
|
|
209
292
|
onAccess?.([strKey]);
|
|
@@ -224,10 +307,10 @@ function defineStore(id, options) {
|
|
|
224
307
|
activeGetterKey = strKey;
|
|
225
308
|
try {
|
|
226
309
|
const onGetterAccess = (path) => {
|
|
227
|
-
dependencies.add(path
|
|
310
|
+
dependencies.add(path);
|
|
228
311
|
};
|
|
229
312
|
const trackingProxyForThis = createStoreProxy(onGetterAccess);
|
|
230
|
-
const trackingStateProxy = createStateProxy(state, [], onGetterAccess);
|
|
313
|
+
const trackingStateProxy = createStateProxy(state, [], onGetterAccess, true);
|
|
231
314
|
const result = getters[strKey].call(trackingProxyForThis, trackingStateProxy);
|
|
232
315
|
localScope.getterDependencies.set(strKey, dependencies);
|
|
233
316
|
localScope.getterResultCache.set(strKey, result);
|
|
@@ -249,6 +332,7 @@ function defineStore(id, options) {
|
|
|
249
332
|
console.warn(`[${id}] Do not replace "$state" directly. Use "$patch()" to replace the whole state.`);
|
|
250
333
|
return false;
|
|
251
334
|
}
|
|
335
|
+
if (strKey === "$id") return readonlyWarning();
|
|
252
336
|
if (strKey in localScope.currentState || strKey in getters || strKey in wrappedActions) {
|
|
253
337
|
return readonlyWarning();
|
|
254
338
|
}
|
|
@@ -261,25 +345,41 @@ function defineStore(id, options) {
|
|
|
261
345
|
const originalAction = originalActions[actionName];
|
|
262
346
|
wrappedActions[actionName] = (...args) => {
|
|
263
347
|
let returnValue;
|
|
348
|
+
let draftActive = true;
|
|
349
|
+
const meta = { type: "action", action: actionName, args };
|
|
264
350
|
const recipe = (draft) => {
|
|
265
351
|
const actionContextProxy = new Proxy({}, {
|
|
266
352
|
get(_, key) {
|
|
267
353
|
const strKey = String(key);
|
|
268
|
-
if (Reflect.has(draft, strKey)) return draft[strKey];
|
|
354
|
+
if (draftActive && Reflect.has(draft, strKey)) return draft[strKey];
|
|
355
|
+
if (!draftActive && Reflect.has(localScope.currentState, strKey)) {
|
|
356
|
+
const value = localScope.currentState[strKey];
|
|
357
|
+
if (value !== null && typeof value === "object") return createActionStateProxy([strKey], meta);
|
|
358
|
+
return value;
|
|
359
|
+
}
|
|
269
360
|
if (strKey in getters) {
|
|
270
|
-
return getters[strKey].call(actionContextProxy, draft);
|
|
361
|
+
if (draftActive) return getters[strKey].call(actionContextProxy, draft);
|
|
362
|
+
return Reflect.get(storePublicApi, key, storePublicApi);
|
|
271
363
|
}
|
|
272
364
|
return Reflect.get(storePublicApi, key, storePublicApi);
|
|
273
365
|
},
|
|
274
366
|
set(_, key, value) {
|
|
275
|
-
;
|
|
276
|
-
draft[
|
|
367
|
+
const path = [String(key)];
|
|
368
|
+
if (draftActive) draft[path[0]] = value;
|
|
369
|
+
else internalPatch((currentDraft) => setAtPath(currentDraft, path, value), meta);
|
|
370
|
+
return true;
|
|
371
|
+
},
|
|
372
|
+
deleteProperty(_, key) {
|
|
373
|
+
const path = [String(key)];
|
|
374
|
+
if (draftActive) delete draft[path[0]];
|
|
375
|
+
else internalPatch((currentDraft) => deleteAtPath(currentDraft, path), meta);
|
|
277
376
|
return true;
|
|
278
377
|
}
|
|
279
378
|
});
|
|
280
379
|
returnValue = originalAction.apply(actionContextProxy, args);
|
|
281
380
|
};
|
|
282
|
-
internalPatch(recipe,
|
|
381
|
+
internalPatch(recipe, meta);
|
|
382
|
+
draftActive = false;
|
|
283
383
|
return returnValue;
|
|
284
384
|
};
|
|
285
385
|
});
|
|
@@ -301,9 +401,7 @@ function defineStore(id, options) {
|
|
|
301
401
|
}
|
|
302
402
|
function getStore() {
|
|
303
403
|
const pinia = getActivePinia();
|
|
304
|
-
|
|
305
|
-
createStoreInstance();
|
|
306
|
-
}
|
|
404
|
+
ensureStoreInstance(pinia);
|
|
307
405
|
if (activeListenerId && activeGetterKey && activeListenerId !== id) {
|
|
308
406
|
const accessedStoreScope = pinia._scopes.get(id);
|
|
309
407
|
if (accessedStoreScope) {
|
|
@@ -319,9 +417,7 @@ function defineStore(id, options) {
|
|
|
319
417
|
}
|
|
320
418
|
function useStore() {
|
|
321
419
|
const pinia = getActivePinia();
|
|
322
|
-
|
|
323
|
-
createStoreInstance();
|
|
324
|
-
}
|
|
420
|
+
ensureStoreInstance(pinia);
|
|
325
421
|
const currentScope = pinia._scopes.get(id);
|
|
326
422
|
const trackedPaths = useRef(/* @__PURE__ */ new Set());
|
|
327
423
|
trackedPaths.current.clear();
|
|
@@ -330,8 +426,12 @@ function defineStore(id, options) {
|
|
|
330
426
|
const listener = (_state, _prevState, patches) => {
|
|
331
427
|
let shouldUpdate = false;
|
|
332
428
|
for (const path of trackedPaths.current) {
|
|
333
|
-
|
|
334
|
-
|
|
429
|
+
if (path.length === 1 && path[0] === "$state") {
|
|
430
|
+
shouldUpdate = patches.length > 0;
|
|
431
|
+
if (shouldUpdate) break;
|
|
432
|
+
}
|
|
433
|
+
const topKey = path[0];
|
|
434
|
+
if (path.length === 1 && topKey in getters) {
|
|
335
435
|
if (!currentScope.getterResultCache.has(topKey)) {
|
|
336
436
|
shouldUpdate = true;
|
|
337
437
|
break;
|
|
@@ -355,7 +455,7 @@ function defineStore(id, options) {
|
|
|
355
455
|
const getSnapshot = useCallback(() => currentScope.currentState, [currentScope]);
|
|
356
456
|
useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
357
457
|
const trackingProxy = currentScope.createStoreProxy((path) => {
|
|
358
|
-
trackedPaths.current.add(path
|
|
458
|
+
trackedPaths.current.add(path);
|
|
359
459
|
});
|
|
360
460
|
return trackingProxy;
|
|
361
461
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rootStore.ts","../src/createPinia.ts","../src/store.ts"],"sourcesContent":["import type { Pinia } from './types'\n\nexport let activePinia: Pinia | undefined\n\nexport function setActivePinia(pinia: Pinia) {\n activePinia = pinia\n}\n\nexport function getActivePinia(): Pinia {\n if (!activePinia) {\n throw new Error(\n '[pinia-react] getActivePinia was called with no active Pinia. Did you forget to install pinia?\\n' +\n 'const pinia = createPinia() or createPinia() first.\\n'\n )\n }\n return activePinia\n}\n","import { setActivePinia } from './rootStore'\nimport type { MutationListener, Pinia, StateTree, StoreGeneric } from './types'\n\nexport function createPinia(): Pinia {\n const state: Record<string, StateTree> = {}\n const _p: Pinia['_p'] = []\n const _s = new Map<string, StoreGeneric>()\n const _scopes = new Map()\n const _m = new Set<MutationListener>()\n\n const pinia: Pinia = {\n use(plugin) {\n _p.push(plugin)\n return this\n },\n onMutation(listener) {\n _m.add(listener)\n return () => _m.delete(listener)\n },\n _p,\n _s,\n _scopes,\n _m,\n state\n }\n\n setActivePinia(pinia)\n\n return pinia\n}\n","import { type Draft, enablePatches, type Patch, produce, setAutoFreeze } from 'immer'\nimport { useCallback, useRef, useSyncExternalStore } from 'react'\nimport { getActivePinia } from './rootStore'\nimport type {\n DefineStoreOptions,\n MutationEvent,\n MutationMeta,\n PiniaPluginContext,\n RestoreStateOptions,\n StateTree,\n Store,\n StoreDefinitionWithNames,\n StoreScope,\n SubscriptionCallback,\n TransformActions\n} from './types'\n\nenablePatches()\nsetAutoFreeze(false)\n\nlet activeListenerId: string | null = null\nlet activeGetterKey: string | null = null\n\nfunction isAffected(patches: Patch[], trackedPaths: Set<string>): boolean {\n if (trackedPaths.size === 0) return false\n const tracked = Array.from(trackedPaths).map((p) => p.split('.'))\n\n for (const patch of patches) {\n const patchPath = patch.path.map(String)\n for (const trackedPath of tracked) {\n const len = Math.min(patchPath.length, trackedPath.length)\n let isPrefixMatch = true\n for (let i = 0; i < len; i++) {\n if (patchPath[i] !== trackedPath[i]) {\n isPrefixMatch = false\n break\n }\n }\n if (isPrefixMatch) return true\n }\n }\n return false\n}\n\nexport function defineStore<\n Id extends string,\n S extends StateTree,\n G extends Record<string, any> = {},\n A extends Record<string, any> = {}\n>(id: Id, options: DefineStoreOptions<S, G, A>): StoreDefinitionWithNames<Id, S, G, A> {\n const getters = options.getters || ({} as G)\n\n function resolveGetterDependencies(\n getterName: string,\n getterDepsMap: Map<string, Set<string>>,\n visited = new Set<string>()\n ): Set<string> {\n if (visited.has(getterName)) {\n console.warn(`[pinia-react] Circular dependency in getters detected involving: ${getterName}`)\n return new Set()\n }\n visited.add(getterName)\n\n const finalDeps = new Set<string>()\n const directDeps = getterDepsMap.get(getterName)\n\n if (!directDeps) return finalDeps\n\n for (const dep of directDeps) {\n if (dep in getters) {\n const nestedDeps = resolveGetterDependencies(dep, getterDepsMap, visited)\n nestedDeps.forEach((d) => finalDeps.add(d))\n } else {\n finalDeps.add(dep)\n }\n }\n return finalDeps\n }\n\n function createStoreInstance(): Store<Id, S, G, A> {\n const pinia = getActivePinia()\n const initialState = options.state()\n\n let storePublicApi: Store<Id, S, G, A>\n\n const localScope: StoreScope = {\n currentState: initialState,\n listeners: new Set(),\n getterResultCache: new Map(),\n getterDependencies: new Map(),\n subscribers: new Map(),\n createStoreProxy: (_onAccess?: (path: string[]) => void) => storePublicApi as any\n }\n pinia._scopes.set(id, localScope)\n\n const isGetterComputing = new Set<string>()\n\n const emit = (nextState: S, oldState: S, patches: Patch[]) => {\n localScope.listeners.forEach((fn) => fn(nextState, oldState, patches))\n\n localScope.subscribers.forEach((getterKeys, storeId) => {\n const subscriberScope = pinia._scopes.get(storeId)\n if (!subscriberScope) return\n let shouldNotify = false\n getterKeys.forEach((key) => {\n if (subscriberScope.getterResultCache.has(key)) {\n subscriberScope.getterResultCache.delete(key)\n shouldNotify = true\n }\n })\n if (shouldNotify) {\n const oldSubState = subscriberScope.currentState\n const newSubState = { ...oldSubState }\n subscriberScope.currentState = newSubState\n pinia.state[storeId] = newSubState\n\n subscriberScope.listeners.forEach((fn) => fn(newSubState, oldSubState, []))\n }\n })\n }\n\n const internalPatch = (updater: (draft: Draft<S>) => void | S, meta: MutationMeta) => {\n const oldState = localScope.currentState as S\n let patches: Patch[] = []\n\n const nextState = produce(oldState, updater as any, (p) => {\n patches = p\n }) as S\n\n if (patches.length > 0 || meta.type === 'reset') {\n localScope.currentState = nextState\n pinia.state[id] = nextState\n emit(nextState, oldState, patches)\n const event: MutationEvent<S> = {\n storeId: id,\n store: storePublicApi as any,\n state: nextState,\n prevState: oldState,\n patches,\n meta\n }\n pinia._m.forEach((listener) => listener(event))\n }\n }\n\n const $patch = (updater: (draft: Draft<S>) => void) => {\n internalPatch(\n (draft) => {\n updater(draft)\n },\n { type: 'patch' }\n )\n }\n\n const $reset = () => internalPatch(() => options.state(), { type: 'reset' })\n\n const restoreState = (state: S, options: RestoreStateOptions = {}) => {\n internalPatch(() => state, {\n type: options.type ?? 'restore',\n origin: options.origin\n })\n }\n\n const $subscribe = (callback: SubscriptionCallback<S>) => {\n const listener = (state: S, prev: S) => callback(state, prev)\n localScope.listeners.add(listener as any)\n return () => localScope.listeners.delete(listener as any)\n }\n\n const getterInvalidationListener = (_state: S, _prevState: S, patches: Patch[]) => {\n localScope.getterDependencies.forEach((_deps, getterName) => {\n const resolvedDeps = resolveGetterDependencies(getterName, localScope.getterDependencies)\n if (isAffected(patches, resolvedDeps)) {\n localScope.getterResultCache.delete(getterName)\n }\n })\n }\n localScope.listeners.add(getterInvalidationListener as any)\n\n const originalActions = options.actions || ({} as A)\n const wrappedActions = {} as TransformActions<A>\n const proxyTarget = {}\n\n function createStoreProxy(onAccess?: (path: string[]) => void): Store<Id, S, G, A> {\n const readonlyWarning = () => {\n console.warn(`[${id}] Store is read-only. Use actions for mutations.`)\n return false\n }\n\n const createStateProxy = (stateTarget: any, path: string[], onDeepAccess?: (path: string[]) => void): any => {\n return new Proxy(stateTarget, {\n get(obj, key) {\n if (typeof key === 'symbol') return Reflect.get(obj, key)\n const currentPath = [...path, String(key)]\n const value = Reflect.get(obj, key)\n if (typeof value === 'object' && value !== null) {\n return createStateProxy(value, currentPath, onDeepAccess)\n }\n onDeepAccess?.(currentPath)\n return value\n },\n set: readonlyWarning\n })\n }\n\n return new Proxy(proxyTarget as any, {\n get(_target, key, receiver) {\n const strKey = String(key)\n\n if (strKey === '$state') return localScope.currentState\n if (strKey === '$patch') return $patch\n if (strKey === '$reset') return $reset\n if (strKey === '$subscribe') return $subscribe\n\n const state = localScope.currentState\n if (strKey in state) {\n const value = state[strKey]\n if (typeof value === 'object' && value !== null) {\n return createStateProxy(value, [strKey], onAccess)\n }\n onAccess?.([strKey])\n return value\n }\n\n if (strKey in getters) {\n onAccess?.([strKey])\n if (localScope.getterResultCache.has(strKey)) return localScope.getterResultCache.get(strKey)\n if (isGetterComputing.has(strKey)) {\n console.warn(`[pinia-react] Circular dependency detected in getter \"${strKey}\"`)\n return undefined\n }\n\n isGetterComputing.add(strKey)\n const dependencies = new Set<string>()\n const prevListenerId = activeListenerId\n const prevGetterKey = activeGetterKey\n activeListenerId = id\n activeGetterKey = strKey\n\n try {\n const onGetterAccess = (path: string[]) => {\n dependencies.add(path[0])\n }\n const trackingProxyForThis = createStoreProxy(onGetterAccess)\n const trackingStateProxy = createStateProxy(state, [], onGetterAccess)\n const result = (getters as any)[strKey].call(trackingProxyForThis, trackingStateProxy)\n\n localScope.getterDependencies.set(strKey, dependencies)\n localScope.getterResultCache.set(strKey, result)\n return result\n } finally {\n activeListenerId = prevListenerId\n activeGetterKey = prevGetterKey\n isGetterComputing.delete(strKey)\n }\n }\n\n if (strKey in wrappedActions) {\n return (wrappedActions as any)[strKey]\n }\n\n return Reflect.get(_target, key, receiver)\n },\n set(_target, key, value, receiver) {\n const strKey = String(key)\n if (strKey === '$state') {\n console.warn(`[${id}] Do not replace \"$state\" directly. Use \"$patch()\" to replace the whole state.`)\n return false\n }\n if (strKey in localScope.currentState || strKey in getters || strKey in wrappedActions) {\n return readonlyWarning()\n }\n return Reflect.set(_target, key, value, receiver)\n }\n }) as Store<Id, S, G, A>\n }\n\n storePublicApi = createStoreProxy()\n\n Object.keys(originalActions).forEach((actionName) => {\n const originalAction = (originalActions as any)[actionName]\n ;(wrappedActions as any)[actionName] = (...args: any[]) => {\n let returnValue: any\n const recipe = (draft: Draft<S>) => {\n const actionContextProxy = new Proxy({} as any, {\n get(_, key) {\n const strKey = String(key)\n if (Reflect.has(draft, strKey)) return (draft as any)[strKey]\n if (strKey in getters) {\n return (getters as any)[strKey].call(actionContextProxy, draft)\n }\n return Reflect.get(storePublicApi, key, storePublicApi)\n },\n set(_, key, value) {\n ;(draft as any)[String(key)] = value\n return true\n }\n })\n returnValue = originalAction.apply(actionContextProxy, args)\n }\n internalPatch(recipe, { type: 'action', action: actionName, args })\n return returnValue\n }\n })\n\n localScope.createStoreProxy = createStoreProxy as any\n\n pinia._p.forEach((plugin) => {\n const pluginResult = plugin({\n id,\n store: storePublicApi,\n options,\n pinia,\n restoreState\n } as PiniaPluginContext)\n if (pluginResult) {\n Object.defineProperties(proxyTarget, Object.getOwnPropertyDescriptors(pluginResult))\n }\n })\n\n pinia._s.set(id, storePublicApi as any)\n\n return storePublicApi\n }\n\n function getStore(): Store<Id, S, G, A> {\n const pinia = getActivePinia()\n\n if (!pinia._s.has(id)) {\n createStoreInstance()\n }\n\n if (activeListenerId && activeGetterKey && activeListenerId !== id) {\n const accessedStoreScope = pinia._scopes.get(id)\n if (accessedStoreScope) {\n let subscribers = accessedStoreScope.subscribers.get(activeListenerId)\n if (!subscribers) {\n subscribers = new Set()\n accessedStoreScope.subscribers.set(activeListenerId, subscribers)\n }\n subscribers.add(activeGetterKey)\n }\n }\n\n return pinia._s.get(id) as Store<Id, S, G, A>\n }\n\n function useStore(): Store<Id, S, G, A> {\n const pinia = getActivePinia()\n if (!pinia._s.has(id)) {\n createStoreInstance()\n }\n const currentScope = pinia._scopes.get(id)!\n\n const trackedPaths = useRef(new Set<string>())\n trackedPaths.current.clear()\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n const listener = (_state: S, _prevState: S, patches: Patch[]) => {\n let shouldUpdate = false\n for (const path of trackedPaths.current) {\n const topKey = path.split('.')[0]\n if (topKey in getters) {\n if (!currentScope.getterResultCache.has(topKey)) {\n shouldUpdate = true\n break\n }\n } else {\n if (patches.length > 0 && isAffected(patches, new Set([path]))) {\n shouldUpdate = true\n break\n }\n }\n }\n if (shouldUpdate) {\n onStoreChange()\n }\n }\n currentScope.listeners.add(listener as any)\n return () => currentScope.listeners.delete(listener as any)\n },\n [currentScope]\n )\n\n const getSnapshot = useCallback(() => currentScope.currentState, [currentScope])\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n\n const trackingProxy = currentScope.createStoreProxy((path) => {\n trackedPaths.current.add(path.join('.'))\n })\n\n return trackingProxy as Store<Id, S, G, A>\n }\n\n const storeName = (id.charAt(0).toUpperCase() + id.slice(1)) as Capitalize<Id>\n\n const definition: StoreDefinitionWithNames<Id, S, G, A> = Object.assign(\n { useStore, getStore },\n {\n [`use${storeName}Store`]: useStore,\n [`get${storeName}Store`]: getStore\n }\n ) as unknown as StoreDefinitionWithNames<Id, S, G, A>\n\n return definition\n}\n"],"mappings":";AAEO,IAAI;AAEJ,SAAS,eAAe,OAAc;AAC3C,gBAAc;AAChB;AAEO,SAAS,iBAAwB;AACtC,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,SAAO;AACT;;;ACbO,SAAS,cAAqB;AACnC,QAAM,QAAmC,CAAC;AAC1C,QAAM,KAAkB,CAAC;AACzB,QAAM,KAAK,oBAAI,IAA0B;AACzC,QAAM,UAAU,oBAAI,IAAI;AACxB,QAAM,KAAK,oBAAI,IAAsB;AAErC,QAAM,QAAe;AAAA,IACnB,IAAI,QAAQ;AACV,SAAG,KAAK,MAAM;AACd,aAAO;AAAA,IACT;AAAA,IACA,WAAW,UAAU;AACnB,SAAG,IAAI,QAAQ;AACf,aAAO,MAAM,GAAG,OAAO,QAAQ;AAAA,IACjC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,iBAAe,KAAK;AAEpB,SAAO;AACT;;;AC7BA,SAAqB,eAA2B,SAAS,qBAAqB;AAC9E,SAAS,aAAa,QAAQ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D,mBAAa,QAAQ,IAAI,KAAK,KAAK,GAAG,CAAC;AAAA,IACzC,CAAC;AAED,WAAO;AAAA,EACT;AAEA,QAAM,YAAa,GAAG,OAAO,CAAC,EAAE,YAAY,IAAI,GAAG,MAAM,CAAC;AAE1D,QAAM,aAAoD,OAAO;AAAA,IAC/D,EAAE,UAAU,SAAS;AAAA,IACrB;AAAA,MACE,CAAC,MAAM,SAAS,OAAO,GAAG;AAAA,MAC1B,CAAC,MAAM,SAAS,OAAO,GAAG;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;","names":["options"]}
|
|
1
|
+
{"version":3,"sources":["../src/rootStore.ts","../src/createPinia.ts","../src/store.ts"],"sourcesContent":["import type { Pinia } from './types'\n\nexport let activePinia: Pinia | undefined\n\nexport function setActivePinia(pinia: Pinia) {\n activePinia = pinia\n}\n\nexport function getActivePinia(): Pinia {\n if (!activePinia) {\n throw new Error(\n '[pinia-react] getActivePinia was called with no active Pinia. Did you forget to install pinia?\\n' +\n 'const pinia = createPinia() or createPinia() first.\\n'\n )\n }\n return activePinia\n}\n","import { setActivePinia } from './rootStore'\nimport type { MutationListener, Pinia, StateTree, StoreGeneric } from './types'\n\nexport function createPinia(): Pinia {\n const state: Record<string, StateTree> = {}\n const _p: Pinia['_p'] = []\n const _s = new Map<string, StoreGeneric>()\n const _scopes = new Map()\n const _m = new Set<MutationListener>()\n\n const pinia: Pinia = {\n use(plugin) {\n if (_s.size > 0) {\n console.warn(\n '[pinia-react] A plugin was registered after stores were created. ' +\n 'The new plugin will not be applied to the stores that already exist.'\n )\n }\n _p.push(plugin)\n return this\n },\n onMutation(listener) {\n _m.add(listener)\n return () => _m.delete(listener)\n },\n _p,\n _s,\n _scopes,\n _m,\n state\n }\n\n setActivePinia(pinia)\n\n return pinia\n}\n","import { type Draft, enablePatches, Immer, type Patch } from 'immer'\nimport { useCallback, useRef, useSyncExternalStore } from 'react'\nimport { getActivePinia } from './rootStore'\nimport type {\n DefineStoreOptions,\n MutationEvent,\n MutationMeta,\n Pinia,\n PiniaPluginContext,\n RestoreStateOptions,\n StatePath,\n StateTree,\n Store,\n StoreDefinitionWithNames,\n StoreScope,\n SubscriptionCallback,\n TransformActions\n} from './types'\n\nenablePatches()\n\n// Isolated Immer instance: keeps `autoFreeze: false` out of the host app's global Immer config.\nconst immer = new Immer({ autoFreeze: false })\n\nlet activeListenerId: string | null = null\nlet activeGetterKey: string | null = null\n\nconst storeDefinitionByPinia = new WeakMap<Pinia, Map<string, unknown>>()\n\nfunction isAffected(patches: Patch[], trackedPaths: Set<StatePath>): boolean {\n if (trackedPaths.size === 0) return false\n const tracked = Array.from(trackedPaths)\n\n for (const patch of patches) {\n const patchPath = patch.path.map(String)\n for (const trackedPath of tracked) {\n const len = Math.min(patchPath.length, trackedPath.length)\n let isPrefixMatch = true\n for (let i = 0; i < len; i++) {\n if (patchPath[i] !== trackedPath[i]) {\n isPrefixMatch = false\n break\n }\n }\n if (isPrefixMatch) return true\n }\n }\n return false\n}\n\n// Only plain objects and arrays are safe to wrap in a proxy; Date/Map/Set break their internal slots.\nfunction isPlainObjectOrArray(value: unknown): value is object {\n if (Array.isArray(value)) return true\n if (value === null || typeof value !== 'object') return false\n const proto = Object.getPrototypeOf(value)\n return proto === Object.prototype || proto === null\n}\n\nexport function defineStore<\n Id extends string,\n S extends StateTree,\n G extends Record<string, any> = {},\n A extends Record<string, any> = {}\n>(id: Id, options: DefineStoreOptions<S, G, A>): StoreDefinitionWithNames<Id, S, G, A> {\n const getters = options.getters || ({} as G)\n\n function ensureStoreInstance(pinia: Pinia) {\n if (pinia._s.has(id)) {\n if (storeDefinitionByPinia.get(pinia)?.get(id) === options) return\n console.warn(\n `[pinia-react] Duplicate store id \"${id}\" detected. The new definition replaces the previous store with the same id.`\n )\n }\n createStoreInstance()\n }\n\n function resolveGetterDependencies(\n getterName: string,\n getterDepsMap: Map<string, Set<StatePath>>,\n visited = new Set<string>()\n ): Set<StatePath> {\n if (visited.has(getterName)) {\n console.warn(`[pinia-react] Circular dependency in getters detected involving: ${getterName}`)\n return new Set()\n }\n visited.add(getterName)\n\n const finalDeps = new Set<StatePath>()\n const directDeps = getterDepsMap.get(getterName)\n\n if (!directDeps) return finalDeps\n\n for (const dep of directDeps) {\n const getterKey = dep.length === 1 ? dep[0] : undefined\n if (getterKey && getterKey in getters) {\n const nestedDeps = resolveGetterDependencies(getterKey, getterDepsMap, visited)\n nestedDeps.forEach((d) => finalDeps.add(d))\n } else {\n finalDeps.add(dep)\n }\n }\n return finalDeps\n }\n\n function createStoreInstance(): Store<Id, S, G, A> {\n const pinia = getActivePinia()\n const initialState = options.state()\n\n let storePublicApi: Store<Id, S, G, A>\n\n const localScope: StoreScope = {\n currentState: initialState,\n listeners: new Set(),\n getterResultCache: new Map(),\n getterDependencies: new Map(),\n subscribers: new Map(),\n createStoreProxy: (_onAccess?: (path: StatePath) => void) => storePublicApi as any\n }\n pinia._scopes.set(id, localScope)\n\n let definitionsById = storeDefinitionByPinia.get(pinia)\n if (!definitionsById) {\n definitionsById = new Map()\n storeDefinitionByPinia.set(pinia, definitionsById)\n }\n definitionsById.set(id, options)\n\n const isGetterComputing = new Set<string>()\n\n const emit = (nextState: S, oldState: S, patches: Patch[]) => {\n localScope.listeners.forEach((fn) => fn(nextState, oldState, patches))\n\n localScope.subscribers.forEach((getterKeys, storeId) => {\n const subscriberScope = pinia._scopes.get(storeId)\n if (!subscriberScope) return\n let shouldNotify = false\n getterKeys.forEach((key) => {\n if (subscriberScope.getterResultCache.has(key)) {\n subscriberScope.getterResultCache.delete(key)\n shouldNotify = true\n }\n })\n if (shouldNotify) {\n const oldSubState = subscriberScope.currentState\n const newSubState = { ...oldSubState }\n subscriberScope.currentState = newSubState\n pinia.state[storeId] = newSubState\n\n subscriberScope.listeners.forEach((fn) => fn(newSubState, oldSubState, []))\n }\n })\n }\n\n const internalPatch = (updater: (draft: Draft<S>) => void | S, meta: MutationMeta) => {\n const oldState = localScope.currentState as S\n let patches: Patch[] = []\n\n const nextState = immer.produce(oldState, updater as any, (p) => {\n patches = p\n }) as S\n\n if (patches.length > 0 || meta.type === 'reset') {\n localScope.currentState = nextState\n pinia.state[id] = nextState\n emit(nextState, oldState, patches)\n const event: MutationEvent<S> = {\n storeId: id,\n store: storePublicApi as any,\n state: nextState,\n prevState: oldState,\n patches,\n meta\n }\n pinia._m.forEach((listener) => listener(event))\n }\n }\n\n const $patch = (updater: (draft: Draft<S>) => void) => {\n internalPatch(\n (draft) => {\n updater(draft)\n },\n { type: 'patch' }\n )\n }\n\n const $reset = () => internalPatch(() => options.state(), { type: 'reset' })\n\n const restoreState = (state: S, options: RestoreStateOptions = {}) => {\n internalPatch(() => state, {\n type: options.type ?? 'restore',\n origin: options.origin\n })\n }\n\n const $subscribe = (callback: SubscriptionCallback<S>) => {\n const listener = (state: S, prev: S) => callback(state, prev)\n localScope.listeners.add(listener as any)\n return () => localScope.listeners.delete(listener as any)\n }\n\n const getterInvalidationListener = (_state: S, _prevState: S, patches: Patch[]) => {\n localScope.getterDependencies.forEach((_deps, getterName) => {\n const resolvedDeps = resolveGetterDependencies(getterName, localScope.getterDependencies)\n if (isAffected(patches, resolvedDeps)) {\n localScope.getterResultCache.delete(getterName)\n }\n })\n }\n localScope.listeners.add(getterInvalidationListener as any)\n\n const originalActions = options.actions || ({} as A)\n const wrappedActions = {} as TransformActions<A>\n const proxyTarget = {}\n const readonlyStateProxyCache = new WeakMap<object, object>()\n\n const readonlyWarning = () => {\n console.warn(`[${id}] Store is read-only. Use actions for mutations.`)\n throw new TypeError(`[${id}] Store is read-only. Use actions for mutations.`)\n }\n\n const createReadonlyStateProxy = (stateTarget: any): any => {\n const cached = readonlyStateProxyCache.get(stateTarget)\n if (cached) return cached\n\n const proxy = new Proxy(stateTarget, {\n get(obj, key) {\n const value = Reflect.get(obj, key)\n if (isPlainObjectOrArray(value)) return createReadonlyStateProxy(value)\n return value\n },\n set: readonlyWarning,\n deleteProperty: readonlyWarning\n })\n readonlyStateProxyCache.set(stateTarget, proxy)\n return proxy\n }\n\n const getAtPath = (path: StatePath) => {\n let value: any = localScope.currentState\n for (const key of path) value = value[key]\n return value\n }\n\n const setAtPath = (draft: Draft<S>, path: StatePath, value: unknown) => {\n let target: any = draft\n for (let i = 0; i < path.length - 1; i++) target = target[path[i]]\n target[path[path.length - 1]] = value\n }\n\n const deleteAtPath = (draft: Draft<S>, path: StatePath) => {\n let target: any = draft\n for (let i = 0; i < path.length - 1; i++) target = target[path[i]]\n delete target[path[path.length - 1]]\n }\n\n const createActionStateProxy = (path: StatePath, meta: MutationMeta): any => {\n return new Proxy(Array.isArray(getAtPath(path)) ? [] : {}, {\n get(_target, key, receiver) {\n const current = getAtPath(path)\n const value = Reflect.get(current, key, receiver)\n if (typeof key === 'symbol' || !isPlainObjectOrArray(value)) return value\n return createActionStateProxy([...path, String(key)], meta)\n },\n set(_target, key, value) {\n internalPatch((draft) => setAtPath(draft, [...path, String(key)], value), meta)\n return true\n },\n deleteProperty(_target, key) {\n internalPatch((draft) => deleteAtPath(draft, [...path, String(key)]), meta)\n return true\n }\n })\n }\n\n function createStoreProxy(onAccess?: (path: StatePath) => void): Store<Id, S, G, A> {\n const createStateProxy = (\n stateTarget: any,\n path: StatePath,\n onDeepAccess?: (path: StatePath) => void,\n trackObjectAccess = false\n ): any => {\n return new Proxy(stateTarget, {\n get(obj, key) {\n if (typeof key === 'symbol') return Reflect.get(obj, key)\n const currentPath = [...path, String(key)]\n const value = Reflect.get(obj, key)\n if (isPlainObjectOrArray(value)) {\n if (trackObjectAccess) onDeepAccess?.(currentPath)\n return createStateProxy(value, currentPath, onDeepAccess, trackObjectAccess)\n }\n onDeepAccess?.(currentPath)\n return value\n },\n set: readonlyWarning,\n deleteProperty: readonlyWarning\n })\n }\n\n return new Proxy(proxyTarget as any, {\n get(_target, key, receiver) {\n const strKey = String(key)\n\n if (strKey === '$state') {\n onAccess?.(['$state'])\n return createReadonlyStateProxy(localScope.currentState)\n }\n if (strKey === '$id') return id\n if (strKey === '$patch') return $patch\n if (strKey === '$reset') return $reset\n if (strKey === '$subscribe') return $subscribe\n\n const state = localScope.currentState\n if (strKey in state) {\n const value = state[strKey]\n if (isPlainObjectOrArray(value)) {\n return createStateProxy(value, [strKey], onAccess)\n }\n onAccess?.([strKey])\n return value\n }\n\n if (strKey in getters) {\n onAccess?.([strKey])\n if (localScope.getterResultCache.has(strKey)) return localScope.getterResultCache.get(strKey)\n if (isGetterComputing.has(strKey)) {\n console.warn(`[pinia-react] Circular dependency detected in getter \"${strKey}\"`)\n return undefined\n }\n\n isGetterComputing.add(strKey)\n const dependencies = new Set<StatePath>()\n const prevListenerId = activeListenerId\n const prevGetterKey = activeGetterKey\n activeListenerId = id\n activeGetterKey = strKey\n\n try {\n const onGetterAccess = (path: StatePath) => {\n dependencies.add(path)\n }\n const trackingProxyForThis = createStoreProxy(onGetterAccess)\n const trackingStateProxy = createStateProxy(state, [], onGetterAccess, true)\n const result = (getters as any)[strKey].call(trackingProxyForThis, trackingStateProxy)\n\n localScope.getterDependencies.set(strKey, dependencies)\n localScope.getterResultCache.set(strKey, result)\n return result\n } finally {\n activeListenerId = prevListenerId\n activeGetterKey = prevGetterKey\n isGetterComputing.delete(strKey)\n }\n }\n\n if (strKey in wrappedActions) {\n return (wrappedActions as any)[strKey]\n }\n\n return Reflect.get(_target, key, receiver)\n },\n set(_target, key, value, receiver) {\n const strKey = String(key)\n if (strKey === '$state') {\n console.warn(`[${id}] Do not replace \"$state\" directly. Use \"$patch()\" to replace the whole state.`)\n return false\n }\n if (strKey === '$id') return readonlyWarning()\n if (strKey in localScope.currentState || strKey in getters || strKey in wrappedActions) {\n return readonlyWarning()\n }\n return Reflect.set(_target, key, value, receiver)\n }\n }) as Store<Id, S, G, A>\n }\n\n storePublicApi = createStoreProxy()\n\n Object.keys(originalActions).forEach((actionName) => {\n const originalAction = (originalActions as any)[actionName]\n ;(wrappedActions as any)[actionName] = (...args: any[]) => {\n let returnValue: any\n let draftActive = true\n const meta: MutationMeta = { type: 'action', action: actionName, args }\n const recipe = (draft: Draft<S>) => {\n const actionContextProxy = new Proxy({} as any, {\n get(_, key) {\n const strKey = String(key)\n if (draftActive && Reflect.has(draft, strKey)) return (draft as any)[strKey]\n if (!draftActive && Reflect.has(localScope.currentState, strKey)) {\n const value = (localScope.currentState as any)[strKey]\n if (value !== null && typeof value === 'object') return createActionStateProxy([strKey], meta)\n return value\n }\n if (strKey in getters) {\n if (draftActive) return (getters as any)[strKey].call(actionContextProxy, draft)\n return Reflect.get(storePublicApi, key, storePublicApi)\n }\n return Reflect.get(storePublicApi, key, storePublicApi)\n },\n set(_, key, value) {\n const path = [String(key)]\n if (draftActive) (draft as any)[path[0]] = value\n else internalPatch((currentDraft) => setAtPath(currentDraft, path, value), meta)\n return true\n },\n deleteProperty(_, key) {\n const path = [String(key)]\n if (draftActive) delete (draft as any)[path[0]]\n else internalPatch((currentDraft) => deleteAtPath(currentDraft, path), meta)\n return true\n }\n })\n returnValue = originalAction.apply(actionContextProxy, args)\n }\n internalPatch(recipe, meta)\n draftActive = false\n return returnValue\n }\n })\n\n localScope.createStoreProxy = createStoreProxy as any\n\n pinia._p.forEach((plugin) => {\n const pluginResult = plugin({\n id,\n store: storePublicApi,\n options,\n pinia,\n restoreState\n } as PiniaPluginContext)\n if (pluginResult) {\n Object.defineProperties(proxyTarget, Object.getOwnPropertyDescriptors(pluginResult))\n }\n })\n\n pinia._s.set(id, storePublicApi as any)\n\n return storePublicApi\n }\n\n function getStore(): Store<Id, S, G, A> {\n const pinia = getActivePinia()\n ensureStoreInstance(pinia)\n\n if (activeListenerId && activeGetterKey && activeListenerId !== id) {\n const accessedStoreScope = pinia._scopes.get(id)\n if (accessedStoreScope) {\n let subscribers = accessedStoreScope.subscribers.get(activeListenerId)\n if (!subscribers) {\n subscribers = new Set()\n accessedStoreScope.subscribers.set(activeListenerId, subscribers)\n }\n subscribers.add(activeGetterKey)\n }\n }\n\n return pinia._s.get(id) as Store<Id, S, G, A>\n }\n\n function useStore(): Store<Id, S, G, A> {\n const pinia = getActivePinia()\n ensureStoreInstance(pinia)\n const currentScope = pinia._scopes.get(id)!\n\n const trackedPaths = useRef(new Set<StatePath>())\n trackedPaths.current.clear()\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n const listener = (_state: S, _prevState: S, patches: Patch[]) => {\n let shouldUpdate = false\n for (const path of trackedPaths.current) {\n if (path.length === 1 && path[0] === '$state') {\n shouldUpdate = patches.length > 0\n if (shouldUpdate) break\n }\n const topKey = path[0]\n if (path.length === 1 && topKey in getters) {\n if (!currentScope.getterResultCache.has(topKey)) {\n shouldUpdate = true\n break\n }\n } else {\n if (patches.length > 0 && isAffected(patches, new Set([path]))) {\n shouldUpdate = true\n break\n }\n }\n }\n if (shouldUpdate) {\n onStoreChange()\n }\n }\n currentScope.listeners.add(listener as any)\n return () => currentScope.listeners.delete(listener as any)\n },\n [currentScope]\n )\n\n const getSnapshot = useCallback(() => currentScope.currentState, [currentScope])\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n\n const trackingProxy = currentScope.createStoreProxy((path) => {\n trackedPaths.current.add(path)\n })\n\n return trackingProxy as Store<Id, S, G, A>\n }\n\n const storeName = (id.charAt(0).toUpperCase() + id.slice(1)) as Capitalize<Id>\n\n const definition: StoreDefinitionWithNames<Id, S, G, A> = Object.assign(\n { useStore, getStore },\n {\n [`use${storeName}Store`]: useStore,\n [`get${storeName}Store`]: getStore\n }\n ) as unknown as StoreDefinitionWithNames<Id, S, G, A>\n\n return definition\n}\n"],"mappings":";AAEO,IAAI;AAEJ,SAAS,eAAe,OAAc;AAC3C,gBAAc;AAChB;AAEO,SAAS,iBAAwB;AACtC,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,SAAO;AACT;;;ACbO,SAAS,cAAqB;AACnC,QAAM,QAAmC,CAAC;AAC1C,QAAM,KAAkB,CAAC;AACzB,QAAM,KAAK,oBAAI,IAA0B;AACzC,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,UAAM,gBAAgB,aAAa,iBAAiB,CAAC,SAAS;AAC5D,mBAAa,QAAQ,IAAI,IAAI;AAAA,IAC/B,CAAC;AAED,WAAO;AAAA,EACT;AAEA,QAAM,YAAa,GAAG,OAAO,CAAC,EAAE,YAAY,IAAI,GAAG,MAAM,CAAC;AAE1D,QAAM,aAAoD,OAAO;AAAA,IAC/D,EAAE,UAAU,SAAS;AAAA,IACrB;AAAA,MACE,CAAC,MAAM,SAAS,OAAO,GAAG;AAAA,MAC1B,CAAC,MAAM,SAAS,OAAO,GAAG;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;","names":["options"]}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinia-react",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Intuitive, type safe and flexible Store for React",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
|
-
"require": "./dist/index.
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
14
|
},
|
|
15
15
|
"./package.json": "./package.json"
|
|
16
16
|
},
|