pinia-react 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 karl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
Binary file
@@ -0,0 +1,64 @@
1
+ //#region src/types.d.ts
2
+
3
+ type StateTree = Record<string | number | symbol, unknown>;
4
+ type _StoreWithGetters<G> = { readonly [k in keyof G]: G[k] extends ((...args: any[]) => infer R) ? R : G[k] };
5
+ type _ActionsTree = Record<string | number | symbol, (...args: any[]) => any>;
6
+ type PiniaCustomStateProperties<S extends StateTree = StateTree> = {};
7
+ type _GettersTree<S extends StateTree> = Record<string, (state: S & PiniaCustomStateProperties<S>) => any>;
8
+ /**
9
+ * Interface to be extended by the user when they add properties through plugins.
10
+ */
11
+ type PiniaCustomProperties<Id extends string = string, S extends StateTree = StateTree, G = _GettersTree<S>, A = _ActionsTree> = {};
12
+ type _DeepPartial<T> = { [K in keyof T]?: _DeepPartial<T[K]> };
13
+ interface _StoreWithState<Id extends string, S extends StateTree, G, A> {
14
+ $id: Id;
15
+ $state: S & PiniaCustomStateProperties<S>;
16
+ $patch(partialState: _DeepPartial<S>): void;
17
+ $patch<F extends (state: S) => any>(stateMutator: ReturnType<F> extends Promise<any> ? never : F): void;
18
+ $reset(): void;
19
+ $subscribe(callback: (newValue: S) => any, options?: {
20
+ detached: boolean;
21
+ }): any;
22
+ }
23
+ type Store<Id extends string, S extends StateTree, G, A> = _StoreWithState<Id, S, G, A> & S & _StoreWithGetters<G> & (_ActionsTree extends A ? {} : A) & PiniaCustomProperties<Id, S, G, A> & PiniaCustomStateProperties<S>;
24
+ type StoreGeneric = Store<string, StateTree, _GettersTree<StateTree>, _ActionsTree>;
25
+ type DefineStoreOptionsBase<S extends StateTree, Store> = {};
26
+ interface DefineStoreOptions<Id extends string, S extends StateTree, G, A> extends DefineStoreOptionsBase<S, Store<Id, S, G, A>> {
27
+ state?: () => S;
28
+ getters?: G & ThisType<S & _StoreWithGetters<G> & PiniaCustomProperties>;
29
+ actions?: A & ThisType<A & S & _StoreWithState<Id, S, G, A> & _StoreWithGetters<G> & PiniaCustomProperties>;
30
+ }
31
+ /**
32
+ * Return type of `defineStore()`. Function that allows instantiating a store.
33
+ */
34
+ interface StoreDefinition<Id extends string = string, S extends StateTree = StateTree, G = _GettersTree<S>, A = _ActionsTree> {
35
+ /**
36
+ * Returns a store, creates it if necessary.
37
+ */
38
+ (): Store<Id, S, G, A>;
39
+ /**
40
+ * Id of the store. Used by map helpers.
41
+ */
42
+ $id: Id;
43
+ }
44
+ type PiniaPluginContext<Id extends string = string, S extends StateTree = StateTree, G = _GettersTree<S>, A = _ActionsTree> = {
45
+ options: DefineStoreOptions<Id, S, G, A>;
46
+ store: Store<Id, S, G, A>;
47
+ };
48
+ type PiniaPlugin = (context: PiniaPluginContext) => Partial<PiniaCustomProperties & PiniaCustomStateProperties> | undefined;
49
+ //#endregion
50
+ //#region src/defineStore.d.ts
51
+ declare function defineStore<Id extends string, S extends StateTree, G extends _GettersTree<S> = {}, A extends _ActionsTree = {}>(id: Id, options: DefineStoreOptions<Id, S, G, A>): StoreDefinition<Id, S, G, A>;
52
+ //#endregion
53
+ //#region src/pinia.d.ts
54
+ interface Pinia {
55
+ _store: Map<string, StoreGeneric>;
56
+ _state: Map<string, StateTree>;
57
+ _plugins: Set<PiniaPlugin>;
58
+ use(plugin: PiniaPlugin): this;
59
+ }
60
+ declare let pinia: Pinia;
61
+ declare function createPinia(): Pinia;
62
+ declare function setActivePinia(_pinia: Pinia): void;
63
+ //#endregion
64
+ export { type DefineStoreOptionsBase, type PiniaCustomProperties, type PiniaCustomStateProperties, type PiniaPlugin, type PiniaPluginContext, type StateTree, type Store, createPinia, defineStore, pinia, setActivePinia };