pinia-react 1.3.1 → 1.4.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.
Files changed (3) hide show
  1. package/README.md +7 -0
  2. package/dist/index.js +2 -1
  3. package/package.json +19 -14
package/README.md CHANGED
@@ -27,6 +27,13 @@ pnpm add pinia-react
27
27
 
28
28
  ## Basic Usage
29
29
 
30
+ ### Initialize
31
+
32
+ ```tsx
33
+ import { createPinia } from 'pinia-react';
34
+ const pinia = createPinia();
35
+ ```
36
+
30
37
  ### Creating and Using a Store
31
38
 
32
39
  ```tsx
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- import{ReactiveEffect as e,activeEffect as t,computed as n,effectScope as r,isReactive as i,isRef as a,markRaw as o,nextTick as s,reactive as c,ref as l,toRaw as u,toRefs as d,watch as f}from"@maoism/runtime-core";import{useCallback as p,useId as m,useRef as h,useSyncExternalStore as g}from"react";import"savage-types";import"savage-utils";const _=()=>v;let v;function y(e){v=e}function b(){let e=r(!0),t=e.run(()=>l({})),n=[],i=o({use(e){return n.push(e),this},_p:n,_e:e,_s:new Map,state:t});return y(i),i}const x=()=>{};function S(e,t,n,r=x){e.add(t);let i=()=>{e.delete(t),r()};return i}function C(e,...t){e.forEach(e=>{e(...t)})}let w=function(e){return e.direct=`direct`,e.patchObject=`patch object`,e.patchFunction=`patch function`,e}({});function T(){return{}}function E(e){return e&&typeof e==`object`&&Object.prototype.toString.call(e)===`[object Object]`&&typeof e.toJSON!=`function`}function D(e,t){for(let n in e instanceof Map&&t instanceof Map&&t.forEach((t,n)=>e.set(n,t)),e instanceof Set&&t instanceof Set&&t.forEach(e.add,e),t){if(!Object.hasOwn(t,n))continue;let r=t[n],o=e[n];E(o)&&E(r)&&e.hasOwnProperty(n)&&!a(r)&&!i(r)?e[n]=D(o,r):e[n]=r}return e}const O=Symbol(),k=Symbol(),{assign:A}=Object;function j(e,t,r){let{state:i,actions:a,getters:s}=t,c=r.state.value[e],l;function u(){c||(r.state.value[e]=i?i():{});let t=d(r.state.value[e]);return A(t,a,Object.keys(s||{}).reduce((t,i)=>(t[i]=o(n(()=>{y(r);let t=r._s.get(e);return s[i].call(t,t)})),t),{}))}return l=M(e,u,t,r),l}function M(e,t,n={},i){let a,o=A({actions:{}},n),l={deep:!0},d,p,m=new Set,h=new Set,g=[],_;function v(t){let n;d=p=!1,typeof t==`function`?(t(i.state.value[e]),n={type:w.patchFunction,storeId:e,events:g}):(D(i.state.value[e],t),n={type:w.patchObject,payload:t,storeId:e,events:g}),_=Symbol();let r=_;s().then(()=>{_===r&&(d=!0)}),p=!0,C(m,n,i.state.value[e])}let b=function(){let{state:e}=n,t=e?e():{};this.$patch(e=>{A(e,t)})},x=(t,n=``)=>{if(O in t)return t[k]=n,t;let r=function(){y(i);let n=Array.from(arguments),a=new Set,o=new Set;function s(e){a.add(e)}function c(e){o.add(e)}C(h,{args:n,name:r[k],store:E,after:s,onError:c});let l;try{l=t.apply(this&&this.$id===e?this:E,n)}catch(e){throw C(o,e),e}return l instanceof Promise?l.then(e=>(C(a,e),e)).catch(e=>(C(o,e),Promise.reject(e))):(C(a,l),l)};return r[O]=!0,r[k]=n,r},T={_p:i,$id:e,$onAction:S.bind(null,h),$patch:v,$reset:b,$subscribe(t,n={}){let r=S(m,t,n.detached,()=>o()),o=a.run(()=>f(()=>i.state.value[e],r=>{(n.flush===`sync`?p:d)&&t({storeId:e,type:w.direct,events:g},r)},A({},l,n)));return r}},E=c(T);i._s.set(e,E),a=r();let j=a.run(()=>t({action:x}));for(let e in j){let t=j[e];if(typeof t==`function`){let n=x(t,e);j[e]=n,o.actions[e]=t}}return A(E,j),A(u(E),j),Object.defineProperty(E,`$state`,{get:()=>i.state.value[e],set:e=>{v(t=>{A(t,e)})}}),i._p.forEach(e=>{A(E,a.run(()=>e({store:E,pinia:i,options:o})))}),d=!0,p=!0,E}function N(n,r){let i=new WeakMap,a=new WeakMap;function o(o){o&&y(o),o=v;let s=t.value;t.value=void 0,o._s.has(n)||j(n,r,o),t.value=s;let c=o._s.get(n),l=h([m()]),u=h({...c}),d=h(!1),f=p(e=>(a.set(l.current,e),()=>{let e=i.get(l.current);e&&e.stop(),a.delete(l.current),i.delete(l.current)}),[]);g(f,()=>u.current,()=>u.current);let _=i.get(l.current);if(!_){let n=()=>{let e=a.get(l.current);d.current||(u.current={...c},e?.())};_=new e(n,T,()=>{_?.dirty&&_.run()}),t.value=_,d.current=!0,_.run(),i.set(l.current,_),d.current=!1}return c}return o.$id=n,o.$getStore=e=>{e&&y(e),e=v,e._s.has(n)||j(n,r,e);let t=e._s.get(n);return t},o}export{w as MutationType,b as createPinia,N as defineStore,_ as getActivePinia,y as setActivePinia};
1
+ import{ReactiveEffect as e,activeEffect as t,computed as n,effectScope as r,isReactive as i,isRef as a,markRaw as o,nextTick as s,reactive as c,ref as l,toRaw as u,toRefs as d,watch as f}from"@maoism/runtime-core";import{useCallback as p,useEffect as m,useId as h,useRef as g,useSyncExternalStore as _}from"react";import"savage-types";import"savage-utils";const v=()=>y;let y;function b(e){y=e}function x(){let e=r(!0),t=e.run(()=>l({})),n=[],i=o({use(e){return n.push(e),this},_p:n,_e:e,_s:new Map,state:t});return b(i),i}const S=()=>{};function C(e,t,n,r,i=S){t.add(n);let a=()=>{t.delete(n),i()};return r||e[0].push(a),a}function w(e,...t){e.forEach(e=>{e(...t)})}let T=function(e){return e.direct=`direct`,e.patchObject=`patch object`,e.patchFunction=`patch function`,e}({});function E(){return{}}function D(e){return e&&typeof e==`object`&&Object.prototype.toString.call(e)===`[object Object]`&&typeof e.toJSON!=`function`}function O(e,t){for(let n in e instanceof Map&&t instanceof Map&&t.forEach((t,n)=>e.set(n,t)),e instanceof Set&&t instanceof Set&&t.forEach(e.add,e),t){if(!Object.hasOwn(t,n))continue;let r=t[n],o=e[n];D(o)&&D(r)&&e.hasOwnProperty(n)&&!a(r)&&!i(r)?e[n]=O(o,r):e[n]=r}return e}const k=Symbol(),A=Symbol(),{assign:j}=Object;function M(e,t,r){let{state:i,actions:a,getters:s}=t,c=r.state.value[e],l;function u(){c||(r.state.value[e]=i?i():{});let t=d(r.state.value[e]);return j(t,a,Object.keys(s||{}).reduce((i,a)=>(a in t&&console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${a}" in store "${e}".`),i[a]=o(n(()=>{b(r);let t=r._s.get(e);return s[a].call(t,t)})),i),{}))}return l=N(e,u,t,r),l}function N(e,t,n={},i){let a,o=j({actions:{}},n),l={deep:!0},d,p,m=new Set,h=new Set,g=[],_;function v(t){let n;d=p=!1,typeof t==`function`?(t(i.state.value[e]),n={type:T.patchFunction,storeId:e,events:g}):(O(i.state.value[e],t),n={type:T.patchObject,payload:t,storeId:e,events:g}),_=Symbol();let r=_;s().then(()=>{_===r&&(d=!0)}),p=!0,w(m,n,i.state.value[e])}let y=function(){let{state:e}=n,t=e?e():{};this.$patch(e=>{j(e,t)})},x=(t,n=``)=>{if(k in t)return t[A]=n,t;let r=function(){b(i);let n=Array.from(arguments),a=new Set,o=new Set;function s(e){a.add(e)}function c(e){o.add(e)}w(h,{args:n,name:r[A],store:E,after:s,onError:c});let l;try{l=t.apply(this&&this.$id===e?this:E,n)}catch(e){throw w(o,e),e}return l instanceof Promise?l.then(e=>(w(a,e),e)).catch(e=>(w(o,e),Promise.reject(e))):(w(a,l),l)};return r[k]=!0,r[A]=n,r},S={_p:i,$id:e,$onAction:C.bind(null,P,h),$patch:v,$reset:y,$subscribe(t,n={}){let r=C([[]],m,t,n.detached,()=>o()),o=a.run(()=>f(()=>i.state.value[e],r=>{(n.flush===`sync`?p:d)&&t({storeId:e,type:T.direct,events:g},r)},j({},l,n)));return r}},E=c(S);i._s.set(e,E),a=r();let D=a.run(()=>t({action:x}));for(let e in D){let t=D[e];if(typeof t==`function`){let n=x(t,e);D[e]=n,o.actions[e]=t}}return j(E,D),j(u(E),D),Object.defineProperty(E,`$state`,{get:()=>i.state.value[e],set:e=>{v(t=>{j(t,e)})}}),i._p.forEach(e=>{j(E,a.run(()=>e({store:E,pinia:i,options:o})))}),d=!0,p=!0,E}const P=[[]];function F(n,r){let i=new WeakMap,a=new WeakMap,o=new WeakMap;function s(s){if(s&&b(s),!y)throw Error(`[🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "createPinia()"?
2
+ `);s=y;let c=t.value;t.value=void 0,s._s.has(n)||M(n,r,s),t.value=c;let l=s._s.get(n),u=g([h()]),d=g({...l}),f=g(!1);o.get(u.current)||o.set(u.current,[]),P[0]=o.get(u.current),m(()=>(P[0]=o.get(u.current),()=>{o.get(u.current).forEach(e=>e())}),[]);let v=p(e=>(a.set(u.current,e),()=>{let e=i.get(u.current);e&&e.stop(),a.delete(u.current),i.delete(u.current)}),[]);_(v,()=>d.current,()=>d.current);let x=i.get(u.current);if(!x){let n=()=>{let e=a.get(u.current);f.current||(d.current={...l},e?.())};x=new e(n,E,()=>{x?.dirty&&x.run()}),t.value=x,f.current=!0,x.run(),i.set(u.current,x),f.current=!1}return l}return s.$id=n,s.$getStore=e=>{e&&b(e),e=y,e._s.has(n)||M(n,r,e);let t=e._s.get(n);return t},s}export{T as MutationType,x as createPinia,F as defineStore,v as getActivePinia,b as setActivePinia};
package/package.json CHANGED
@@ -1,7 +1,19 @@
1
1
  {
2
2
  "name": "pinia-react",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
+ "description": "Intuitive, type safe and flexible Store for React",
5
+ "packageManager": "pnpm@10.14.0",
4
6
  "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": "./dist/index.js",
12
+ "./package.json": "./package.json"
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
5
17
  "homepage": "https://github.com/savageKarl/pinia-react#readme",
6
18
  "bugs": {
7
19
  "url": "https://github.com/savageKarl/pinia-react/issues"
@@ -11,16 +23,6 @@
11
23
  "url": "git+https://github.com/savageKarl/pinia-react.git"
12
24
  },
13
25
  "author": "savageKarl <shan.revolt@gmail.com>",
14
- "files": [
15
- "dist"
16
- ],
17
- "main": "./dist/index.js",
18
- "module": "./dist/index.js",
19
- "types": "./dist/index.d.ts",
20
- "exports": {
21
- ".": "./dist/index.js",
22
- "./package.json": "./package.json"
23
- },
24
26
  "publishConfig": {
25
27
  "access": "public"
26
28
  },
@@ -35,12 +37,15 @@
35
37
  "format": "pnpm exec biome check --write"
36
38
  },
37
39
  "keywords": [
38
- "pinia",
40
+ "react",
41
+ "pinia-react",
39
42
  "react-pinia",
40
- "react-store"
43
+ "react-store",
44
+ "redux",
45
+ "zustand",
46
+ "store"
41
47
  ],
42
48
  "license": "MIT",
43
- "description": "",
44
49
  "simple-git-hooks": {
45
50
  "commit-msg": "npx --no-install commitlint --edit \"$1\""
46
51
  },