@chhsiao1981/use-thunk 9.0.4 → 10.0.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/README.md +52 -55
- package/dist/index.js +1723 -0
- package/dist/index.umd.cjs +50 -0
- package/package.json +2 -2
- package/src/ThunkContext.tsx +34 -0
- package/src/dispatchFuncMap.ts +48 -4
- package/src/index.ts +4 -18
- package/src/init.ts +12 -30
- package/src/reduceMap.ts +0 -14
- package/src/registerThunk.ts +35 -0
- package/src/remove.ts +6 -32
- package/src/setData.ts +1 -1
- package/src/setRoot.ts +4 -1
- package/src/stateTypes.ts +0 -29
- package/src/states.ts +4 -1
- package/src/thunk.ts +1 -1
- package/src/thunkContextMap.ts +22 -0
- package/src/thunkContextTypes.ts +8 -0
- package/src/thunkModuleFuncMap.ts +0 -11
- package/src/useThunk.ts +31 -55
- package/src/useThunkReducer.ts +19 -22
- package/types/ThunkContext.d.ts +7 -0
- package/types/dispatchFuncMap.d.ts +6 -5
- package/types/index.d.ts +3 -8
- package/types/init.d.ts +1 -1
- package/types/registerThunk.d.ts +4 -0
- package/types/remove.d.ts +2 -2
- package/types/setData.d.ts +1 -1
- package/types/stateTypes.d.ts +0 -19
- package/types/thunk.d.ts +1 -1
- package/types/thunkContextMap.d.ts +15 -0
- package/types/thunkContextTypes.d.ts +8 -0
- package/types/thunkModuleFuncMap.d.ts +2 -6
- package/types/useThunk.d.ts +6 -3
- package/types/useThunkReducer.d.ts +3 -4
- package/src/addChild.ts +0 -16
- package/src/addLink.ts +0 -27
- package/src/addRelation.ts +0 -32
- package/src/getRelation.ts +0 -43
- package/src/removeChild.ts +0 -46
- package/src/removeLink.ts +0 -47
- package/src/removeRelation.ts +0 -84
- package/types/addChild.d.ts +0 -5
- package/types/addLink.d.ts +0 -6
- package/types/addRelation.d.ts +0 -6
- package/types/getRelation.d.ts +0 -5
- package/types/reducerModuleFuncMap.d.ts +0 -10
- package/types/removeChild.d.ts +0 -9
- package/types/removeLink.d.ts +0 -9
- package/types/removeRelation.d.ts +0 -12
- package/types/thunk-reducer.d.ts +0 -16
- package/types/thunkReducer.d.ts +0 -18
- package/types/useReducer.d.ts +0 -8
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
(function(P,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(P=typeof globalThis<"u"?globalThis:P||self,A((P["use-thunk"]=P["use-thunk"]||{},P["use-thunk"].js={})))})(this,(function(P){"use strict";const A=[];for(let u=0;u<256;++u)A.push((u+256).toString(16).slice(1));function st(u,n=0){return(A[u[n+0]]+A[u[n+1]]+A[u[n+2]]+A[u[n+3]]+"-"+A[u[n+4]]+A[u[n+5]]+"-"+A[u[n+6]]+A[u[n+7]]+"-"+A[u[n+8]]+A[u[n+9]]+"-"+A[u[n+10]]+A[u[n+11]]+A[u[n+12]]+A[u[n+13]]+A[u[n+14]]+A[u[n+15]]).toLowerCase()}let Re;const at=new Uint8Array(16);function ct(){if(!Re){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Re=crypto.getRandomValues.bind(crypto)}return Re(at)}const be={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function it(u,n,i){var p;if(be.randomUUID&&!n&&!u)return be.randomUUID();u=u||{};const l=u.random??((p=u.rng)==null?void 0:p.call(u))??ct();if(l.length<16)throw new Error("Random bytes length must be >= 16");if(l[6]=l[6]&15|64,l[8]=l[8]&63|128,n){if(i=i||0,i<0||i+16>n.length)throw new RangeError(`UUID byte range ${i}:${i+15} is out of buffer bounds`);for(let _=0;_<16;++_)n[i+_]=l[_];return n}return st(l)}const Oe=new Set,ft=3,Ce={iterate:1},ke=u=>{let n="",i=!1;for(let l=0;l<ft;l++)if(n=Se(u),!Oe.has(n)){Oe.add(n),i=!0;break}return i||(Ce.iterate+=1,n=Se(u)),n},Se=(u=it)=>{let n="";for(let i=0;i<Ce.iterate;i++)n+=u();return n},Ae="@chhsiao1981/use-thunk/SET_ROOT",lt=u=>({myID:u,type:Ae}),dt=(u,n)=>{const{myID:i}=n;return Object.assign({},u,{root:i})},je=(u,n)=>(i,l)=>{const p=u.myID??ke(n),{state:_}=u;i(pt(p,_));const{root:T}=l();T||i(lt(p))},Pe="@chhsiao1981/use-thunk/INIT",pt=(u,n)=>({myID:u,type:Pe,state:n}),_t=(u,n)=>{const{myID:i,state:l}=n,p={id:i,state:l},_=Object.assign({},u.nodes,{[i]:p});return Object.assign({},u,{nodes:_})};var me={exports:{}},y={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react.production.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var Ne;function mt(){if(Ne)return y;Ne=1;var u=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),p=Symbol.for("react.profiler"),_=Symbol.for("react.consumer"),T=Symbol.for("react.context"),k=Symbol.for("react.forward_ref"),M=Symbol.for("react.suspense"),N=Symbol.for("react.memo"),D=Symbol.for("react.lazy"),q=Symbol.for("react.activity"),V=Symbol.iterator;function G(t){return t===null||typeof t!="object"?null:(t=V&&t[V]||t["@@iterator"],typeof t=="function"?t:null)}var Q={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},oe=Object.assign,X={};function W(t,o,c){this.props=t,this.context=o,this.refs=X,this.updater=c||Q}W.prototype.isReactComponent={},W.prototype.setState=function(t,o){if(typeof t!="object"&&typeof t!="function"&&t!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,o,"setState")},W.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function K(){}K.prototype=W.prototype;function ue(t,o,c){this.props=t,this.context=o,this.refs=X,this.updater=c||Q}var Z=ue.prototype=new K;Z.constructor=ue,oe(Z,W.prototype),Z.isPureReactComponent=!0;var Y=Array.isArray;function se(){}var b={H:null,A:null,T:null,S:null},ie=Object.prototype.hasOwnProperty;function U(t,o,c){var f=c.ref;return{$$typeof:u,type:t,key:o,ref:f!==void 0?f:null,props:c}}function J(t,o){return U(t.type,o,t.props)}function ae(t){return typeof t=="object"&&t!==null&&t.$$typeof===u}function O(t){var o={"=":"=0",":":"=2"};return"$"+t.replace(/[=:]/g,function(c){return o[c]})}var ee=/\/+/g;function z(t,o){return typeof t=="object"&&t!==null&&t.key!=null?O(""+t.key):o.toString(36)}function H(t){switch(t.status){case"fulfilled":return t.value;case"rejected":throw t.reason;default:switch(typeof t.status=="string"?t.then(se,se):(t.status="pending",t.then(function(o){t.status==="pending"&&(t.status="fulfilled",t.value=o)},function(o){t.status==="pending"&&(t.status="rejected",t.reason=o)})),t.status){case"fulfilled":return t.value;case"rejected":throw t.reason}}throw t}function I(t,o,c,f,h){var w=typeof t;(w==="undefined"||w==="boolean")&&(t=null);var m=!1;if(t===null)m=!0;else switch(w){case"bigint":case"string":case"number":m=!0;break;case"object":switch(t.$$typeof){case u:case n:m=!0;break;case D:return m=t._init,I(m(t._payload),o,c,f,h)}}if(m)return h=h(t),m=f===""?"."+z(t,0):f,Y(h)?(c="",m!=null&&(c=m.replace(ee,"$&/")+"/"),I(h,o,c,"",function(B){return B})):h!=null&&(ae(h)&&(h=J(h,c+(h.key==null||t&&t.key===h.key?"":(""+h.key).replace(ee,"$&/")+"/")+m)),o.push(h)),1;m=0;var j=f===""?".":f+":";if(Y(t))for(var S=0;S<t.length;S++)f=t[S],w=j+z(f,S),m+=I(f,o,c,w,h);else if(S=G(t),typeof S=="function")for(t=S.call(t),S=0;!(f=t.next()).done;)f=f.value,w=j+z(f,S++),m+=I(f,o,c,w,h);else if(w==="object"){if(typeof t.then=="function")return I(H(t),o,c,f,h);throw o=String(t),Error("Objects are not valid as a React child (found: "+(o==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":o)+"). If you meant to render a collection of children, use an array instead.")}return m}function x(t,o,c){if(t==null)return t;var f=[],h=0;return I(t,f,"","",function(w){return o.call(c,w,h++)}),f}function te(t){if(t._status===-1){var o=t._result;o=o(),o.then(function(c){(t._status===0||t._status===-1)&&(t._status=1,t._result=c)},function(c){(t._status===0||t._status===-1)&&(t._status=2,t._result=c)}),t._status===-1&&(t._status=0,t._result=o)}if(t._status===1)return t._result.default;throw t._result}var F=typeof reportError=="function"?reportError:function(t){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var o=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof t=="object"&&t!==null&&typeof t.message=="string"?String(t.message):String(t),error:t});if(!window.dispatchEvent(o))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",t);return}console.error(t)},ce={map:x,forEach:function(t,o,c){x(t,function(){o.apply(this,arguments)},c)},count:function(t){var o=0;return x(t,function(){o++}),o},toArray:function(t){return x(t,function(o){return o})||[]},only:function(t){if(!ae(t))throw Error("React.Children.only expected to receive a single React element child.");return t}};return y.Activity=q,y.Children=ce,y.Component=W,y.Fragment=i,y.Profiler=p,y.PureComponent=ue,y.StrictMode=l,y.Suspense=M,y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=b,y.__COMPILER_RUNTIME={__proto__:null,c:function(t){return b.H.useMemoCache(t)}},y.cache=function(t){return function(){return t.apply(null,arguments)}},y.cacheSignal=function(){return null},y.cloneElement=function(t,o,c){if(t==null)throw Error("The argument must be a React element, but you passed "+t+".");var f=oe({},t.props),h=t.key;if(o!=null)for(w in o.key!==void 0&&(h=""+o.key),o)!ie.call(o,w)||w==="key"||w==="__self"||w==="__source"||w==="ref"&&o.ref===void 0||(f[w]=o[w]);var w=arguments.length-2;if(w===1)f.children=c;else if(1<w){for(var m=Array(w),j=0;j<w;j++)m[j]=arguments[j+2];f.children=m}return U(t.type,h,f)},y.createContext=function(t){return t={$$typeof:T,_currentValue:t,_currentValue2:t,_threadCount:0,Provider:null,Consumer:null},t.Provider=t,t.Consumer={$$typeof:_,_context:t},t},y.createElement=function(t,o,c){var f,h={},w=null;if(o!=null)for(f in o.key!==void 0&&(w=""+o.key),o)ie.call(o,f)&&f!=="key"&&f!=="__self"&&f!=="__source"&&(h[f]=o[f]);var m=arguments.length-2;if(m===1)h.children=c;else if(1<m){for(var j=Array(m),S=0;S<m;S++)j[S]=arguments[S+2];h.children=j}if(t&&t.defaultProps)for(f in m=t.defaultProps,m)h[f]===void 0&&(h[f]=m[f]);return U(t,w,h)},y.createRef=function(){return{current:null}},y.forwardRef=function(t){return{$$typeof:k,render:t}},y.isValidElement=ae,y.lazy=function(t){return{$$typeof:D,_payload:{_status:-1,_result:t},_init:te}},y.memo=function(t,o){return{$$typeof:N,type:t,compare:o===void 0?null:o}},y.startTransition=function(t){var o=b.T,c={};b.T=c;try{var f=t(),h=b.S;h!==null&&h(c,f),typeof f=="object"&&f!==null&&typeof f.then=="function"&&f.then(se,F)}catch(w){F(w)}finally{o!==null&&c.types!==null&&(o.types=c.types),b.T=o}},y.unstable_useCacheRefresh=function(){return b.H.useCacheRefresh()},y.use=function(t){return b.H.use(t)},y.useActionState=function(t,o,c){return b.H.useActionState(t,o,c)},y.useCallback=function(t,o){return b.H.useCallback(t,o)},y.useContext=function(t){return b.H.useContext(t)},y.useDebugValue=function(){},y.useDeferredValue=function(t,o){return b.H.useDeferredValue(t,o)},y.useEffect=function(t,o){return b.H.useEffect(t,o)},y.useEffectEvent=function(t){return b.H.useEffectEvent(t)},y.useId=function(){return b.H.useId()},y.useImperativeHandle=function(t,o,c){return b.H.useImperativeHandle(t,o,c)},y.useInsertionEffect=function(t,o){return b.H.useInsertionEffect(t,o)},y.useLayoutEffect=function(t,o){return b.H.useLayoutEffect(t,o)},y.useMemo=function(t,o){return b.H.useMemo(t,o)},y.useOptimistic=function(t,o){return b.H.useOptimistic(t,o)},y.useReducer=function(t,o,c){return b.H.useReducer(t,o,c)},y.useRef=function(t){return b.H.useRef(t)},y.useState=function(t){return b.H.useState(t)},y.useSyncExternalStore=function(t,o,c){return b.H.useSyncExternalStore(t,o,c)},y.useTransition=function(){return b.H.useTransition()},y.version="19.2.0",y}var le={exports:{}};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/le.exports;var Me;function yt(){return Me||(Me=1,(function(u,n){process.env.NODE_ENV!=="production"&&(function(){function i(e,r){Object.defineProperty(_.prototype,e,{get:function(){console.warn("%s(...) is deprecated in plain JavaScript React classes. %s",r[0],r[1])}})}function l(e){return e===null||typeof e!="object"?null:(e=Fe&&e[Fe]||e["@@iterator"],typeof e=="function"?e:null)}function p(e,r){e=(e=e.constructor)&&(e.displayName||e.name)||"ReactClass";var s=e+"."+r;Be[s]||(console.error("Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.",r,e),Be[s]=!0)}function _(e,r,s){this.props=e,this.context=r,this.refs=Te,this.updater=s||Ve}function T(){}function k(e,r,s){this.props=e,this.context=r,this.refs=Te,this.updater=s||Ve}function M(){}function N(e){return""+e}function D(e){try{N(e);var r=!1}catch{r=!0}if(r){r=console;var s=r.error,a=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return s.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",a),N(e)}}function q(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===It?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case t:return"Fragment";case c:return"Profiler";case o:return"StrictMode";case m:return"Suspense";case j:return"SuspenseList";case Ge:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case ce:return"Portal";case h:return e.displayName||"Context";case f:return(e._context.displayName||"Context")+".Consumer";case w:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case S:return r=e.displayName||null,r!==null?r:q(e.type)||"Memo";case B:r=e._payload,e=e._init;try{return q(e(r))}catch{}}return null}function V(e){if(e===t)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===B)return"<...>";try{var r=q(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function G(){var e=v.A;return e===null?null:e.getOwner()}function Q(){return Error("react-stack-top-frame")}function oe(e){if(Ee.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function X(e,r){function s(){Ze||(Ze=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}s.isReactWarning=!0,Object.defineProperty(e,"key",{get:s,configurable:!0})}function W(){var e=q(this.type);return et[e]||(et[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function K(e,r,s,a,d,g){var E=s.ref;return e={$$typeof:F,type:e,key:r,props:s,_owner:a},(E!==void 0?E:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:W}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:d}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:g}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function ue(e,r){return r=K(e.type,r,e.props,e._owner,e._debugStack,e._debugTask),e._store&&(r._store.validated=e._store.validated),r}function Z(e){Y(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===B&&(e._payload.status==="fulfilled"?Y(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function Y(e){return typeof e=="object"&&e!==null&&e.$$typeof===F}function se(e){var r={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return r[s]})}function b(e,r){return typeof e=="object"&&e!==null&&e.key!=null?(D(e.key),se(""+e.key)):r.toString(36)}function ie(e){switch(e.status){case"fulfilled":return e.value;case"rejected":throw e.reason;default:switch(typeof e.status=="string"?e.then(M,M):(e.status="pending",e.then(function(r){e.status==="pending"&&(e.status="fulfilled",e.value=r)},function(r){e.status==="pending"&&(e.status="rejected",e.reason=r)})),e.status){case"fulfilled":return e.value;case"rejected":throw e.reason}}throw e}function U(e,r,s,a,d){var g=typeof e;(g==="undefined"||g==="boolean")&&(e=null);var E=!1;if(e===null)E=!0;else switch(g){case"bigint":case"string":case"number":E=!0;break;case"object":switch(e.$$typeof){case F:case ce:E=!0;break;case B:return E=e._init,U(E(e._payload),r,s,a,d)}}if(E){E=e,d=d(E);var C=a===""?"."+b(E,0):a;return Xe(d)?(s="",C!=null&&(s=C.replace(rt,"$&/")+"/"),U(d,r,s,"",function(re){return re})):d!=null&&(Y(d)&&(d.key!=null&&(E&&E.key===d.key||D(d.key)),s=ue(d,s+(d.key==null||E&&E.key===d.key?"":(""+d.key).replace(rt,"$&/")+"/")+C),a!==""&&E!=null&&Y(E)&&E.key==null&&E._store&&!E._store.validated&&(s._store.validated=2),d=s),r.push(d)),1}if(E=0,C=a===""?".":a+":",Xe(e))for(var R=0;R<e.length;R++)a=e[R],g=C+b(a,R),E+=U(a,r,s,g,d);else if(R=l(e),typeof R=="function")for(R===e.entries&&(tt||console.warn("Using Maps as children is not supported. Use an array of keyed ReactElements instead."),tt=!0),e=R.call(e),R=0;!(a=e.next()).done;)a=a.value,g=C+b(a,R++),E+=U(a,r,s,g,d);else if(g==="object"){if(typeof e.then=="function")return U(ie(e),r,s,a,d);throw r=String(e),Error("Objects are not valid as a React child (found: "+(r==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":r)+"). If you meant to render a collection of children, use an array instead.")}return E}function J(e,r,s){if(e==null)return e;var a=[],d=0;return U(e,a,"","",function(g){return r.call(s,g,d++)}),a}function ae(e){if(e._status===-1){var r=e._ioInfo;r!=null&&(r.start=r.end=performance.now()),r=e._result;var s=r();if(s.then(function(d){if(e._status===0||e._status===-1){e._status=1,e._result=d;var g=e._ioInfo;g!=null&&(g.end=performance.now()),s.status===void 0&&(s.status="fulfilled",s.value=d)}},function(d){if(e._status===0||e._status===-1){e._status=2,e._result=d;var g=e._ioInfo;g!=null&&(g.end=performance.now()),s.status===void 0&&(s.status="rejected",s.reason=d)}}),r=e._ioInfo,r!=null){r.value=s;var a=s.displayName;typeof a=="string"&&(r.name=a)}e._status===-1&&(e._status=0,e._result=s)}if(e._status===1)return r=e._result,r===void 0&&console.error(`lazy: Expected the result of a dynamic import() call. Instead received: %s
|
|
18
|
+
|
|
19
|
+
Your code should look like:
|
|
20
|
+
const MyComponent = lazy(() => import('./MyComponent'))
|
|
21
|
+
|
|
22
|
+
Did you accidentally put curly braces around the import?`,r),"default"in r||console.error(`lazy: Expected the result of a dynamic import() call. Instead received: %s
|
|
23
|
+
|
|
24
|
+
Your code should look like:
|
|
25
|
+
const MyComponent = lazy(() => import('./MyComponent'))`,r),r.default;throw e._result}function O(){var e=v.H;return e===null&&console.error(`Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
|
|
26
|
+
1. You might have mismatching versions of React and the renderer (such as React DOM)
|
|
27
|
+
2. You might be breaking the Rules of Hooks
|
|
28
|
+
3. You might have more than one copy of React in the same app
|
|
29
|
+
See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.`),e}function ee(){v.asyncTransitions--}function z(e){if(he===null)try{var r=("require"+Math.random()).slice(0,7);he=(u&&u[r]).call(u,"timers").setImmediate}catch{he=function(a){ot===!1&&(ot=!0,typeof MessageChannel>"u"&&console.error("This browser does not have a MessageChannel implementation, so enqueuing tasks via await act(async () => ...) will fail. Please file an issue at https://github.com/facebook/react/issues if you encounter this warning."));var d=new MessageChannel;d.port1.onmessage=a,d.port2.postMessage(void 0)}}return he(e)}function H(e){return 1<e.length&&typeof AggregateError=="function"?new AggregateError(e):e[0]}function I(e,r){r!==ve-1&&console.error("You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one. "),ve=r}function x(e,r,s){var a=v.actQueue;if(a!==null)if(a.length!==0)try{te(a),z(function(){return x(e,r,s)});return}catch(d){v.thrownErrors.push(d)}else v.actQueue=null;0<v.thrownErrors.length?(a=H(v.thrownErrors),v.thrownErrors.length=0,s(a)):r(e)}function te(e){if(!we){we=!0;var r=0;try{for(;r<e.length;r++){var s=e[r];do{v.didUsePromise=!1;var a=s(!1);if(a!==null){if(v.didUsePromise){e[r]=s,e.splice(0,r);return}s=a}else break}while(!0)}e.length=0}catch(d){e.splice(0,r+1),v.thrownErrors.push(d)}finally{we=!1}}}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var F=Symbol.for("react.transitional.element"),ce=Symbol.for("react.portal"),t=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),f=Symbol.for("react.consumer"),h=Symbol.for("react.context"),w=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),j=Symbol.for("react.suspense_list"),S=Symbol.for("react.memo"),B=Symbol.for("react.lazy"),Ge=Symbol.for("react.activity"),Fe=Symbol.iterator,Be={},Ve={isMounted:function(){return!1},enqueueForceUpdate:function(e){p(e,"forceUpdate")},enqueueReplaceState:function(e){p(e,"replaceState")},enqueueSetState:function(e){p(e,"setState")}},Qe=Object.assign,Te={};Object.freeze(Te),_.prototype.isReactComponent={},_.prototype.setState=function(e,r){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,r,"setState")},_.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};var L={isMounted:["isMounted","Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."],replaceState:["replaceState","Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."]};for(_e in L)L.hasOwnProperty(_e)&&i(_e,L[_e]);T.prototype=_.prototype,L=k.prototype=new T,L.constructor=k,Qe(L,_.prototype),L.isPureReactComponent=!0;var Xe=Array.isArray,It=Symbol.for("react.client.reference"),v={H:null,A:null,T:null,S:null,actQueue:null,asyncTransitions:0,isBatchingLegacy:!1,didScheduleLegacyUpdate:!1,didUsePromise:!1,thrownErrors:[],getCurrentStack:null,recentlyCreatedOwnerStacks:0},Ee=Object.prototype.hasOwnProperty,Ke=console.createTask?console.createTask:function(){return null};L={react_stack_bottom_frame:function(e){return e()}};var Ze,Je,et={},Lt=L.react_stack_bottom_frame.bind(L,Q)(),Yt=Ke(V(Q)),tt=!1,rt=/\/+/g,nt=typeof reportError=="function"?reportError:function(e){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var r=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof e=="object"&&e!==null&&typeof e.message=="string"?String(e.message):String(e),error:e});if(!window.dispatchEvent(r))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",e);return}console.error(e)},ot=!1,he=null,ve=0,ge=!1,we=!1,ut=typeof queueMicrotask=="function"?function(e){queueMicrotask(function(){return queueMicrotask(e)})}:z;L=Object.freeze({__proto__:null,c:function(e){return O().useMemoCache(e)}});var _e={map:J,forEach:function(e,r,s){J(e,function(){r.apply(this,arguments)},s)},count:function(e){var r=0;return J(e,function(){r++}),r},toArray:function(e){return J(e,function(r){return r})||[]},only:function(e){if(!Y(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};n.Activity=Ge,n.Children=_e,n.Component=_,n.Fragment=t,n.Profiler=c,n.PureComponent=k,n.StrictMode=o,n.Suspense=m,n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=v,n.__COMPILER_RUNTIME=L,n.act=function(e){var r=v.actQueue,s=ve;ve++;var a=v.actQueue=r!==null?r:[],d=!1;try{var g=e()}catch(R){v.thrownErrors.push(R)}if(0<v.thrownErrors.length)throw I(r,s),e=H(v.thrownErrors),v.thrownErrors.length=0,e;if(g!==null&&typeof g=="object"&&typeof g.then=="function"){var E=g;return ut(function(){d||ge||(ge=!0,console.error("You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);"))}),{then:function(R,re){d=!0,E.then(function(fe){if(I(r,s),s===0){try{te(a),z(function(){return x(fe,R,re)})}catch(xt){v.thrownErrors.push(xt)}if(0<v.thrownErrors.length){var Ht=H(v.thrownErrors);v.thrownErrors.length=0,re(Ht)}}else R(fe)},function(fe){I(r,s),0<v.thrownErrors.length&&(fe=H(v.thrownErrors),v.thrownErrors.length=0),re(fe)})}}}var C=g;if(I(r,s),s===0&&(te(a),a.length!==0&&ut(function(){d||ge||(ge=!0,console.error("A component suspended inside an `act` scope, but the `act` call was not awaited. When testing React components that depend on asynchronous data, you must await the result:\n\nawait act(() => ...)"))}),v.actQueue=null),0<v.thrownErrors.length)throw e=H(v.thrownErrors),v.thrownErrors.length=0,e;return{then:function(R,re){d=!0,s===0?(v.actQueue=a,z(function(){return x(C,R,re)})):R(C)}}},n.cache=function(e){return function(){return e.apply(null,arguments)}},n.cacheSignal=function(){return null},n.captureOwnerStack=function(){var e=v.getCurrentStack;return e===null?null:e()},n.cloneElement=function(e,r,s){if(e==null)throw Error("The argument must be a React element, but you passed "+e+".");var a=Qe({},e.props),d=e.key,g=e._owner;if(r!=null){var E;e:{if(Ee.call(r,"ref")&&(E=Object.getOwnPropertyDescriptor(r,"ref").get)&&E.isReactWarning){E=!1;break e}E=r.ref!==void 0}E&&(g=G()),oe(r)&&(D(r.key),d=""+r.key);for(C in r)!Ee.call(r,C)||C==="key"||C==="__self"||C==="__source"||C==="ref"&&r.ref===void 0||(a[C]=r[C])}var C=arguments.length-2;if(C===1)a.children=s;else if(1<C){E=Array(C);for(var R=0;R<C;R++)E[R]=arguments[R+2];a.children=E}for(a=K(e.type,d,a,g,e._debugStack,e._debugTask),d=2;d<arguments.length;d++)Z(arguments[d]);return a},n.createContext=function(e){return e={$$typeof:h,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:f,_context:e},e._currentRenderer=null,e._currentRenderer2=null,e},n.createElement=function(e,r,s){for(var a=2;a<arguments.length;a++)Z(arguments[a]);a={};var d=null;if(r!=null)for(R in Je||!("__self"in r)||"key"in r||(Je=!0,console.warn("Your app (or one of its dependencies) is using an outdated JSX transform. Update to the modern JSX transform for faster performance: https://react.dev/link/new-jsx-transform")),oe(r)&&(D(r.key),d=""+r.key),r)Ee.call(r,R)&&R!=="key"&&R!=="__self"&&R!=="__source"&&(a[R]=r[R]);var g=arguments.length-2;if(g===1)a.children=s;else if(1<g){for(var E=Array(g),C=0;C<g;C++)E[C]=arguments[C+2];Object.freeze&&Object.freeze(E),a.children=E}if(e&&e.defaultProps)for(R in g=e.defaultProps,g)a[R]===void 0&&(a[R]=g[R]);d&&X(a,typeof e=="function"?e.displayName||e.name||"Unknown":e);var R=1e4>v.recentlyCreatedOwnerStacks++;return K(e,d,a,G(),R?Error("react-stack-top-frame"):Lt,R?Ke(V(e)):Yt)},n.createRef=function(){var e={current:null};return Object.seal(e),e},n.forwardRef=function(e){e!=null&&e.$$typeof===S?console.error("forwardRef requires a render function but received a `memo` component. Instead of forwardRef(memo(...)), use memo(forwardRef(...))."):typeof e!="function"?console.error("forwardRef requires a render function but was given %s.",e===null?"null":typeof e):e.length!==0&&e.length!==2&&console.error("forwardRef render functions accept exactly two parameters: props and ref. %s",e.length===1?"Did you forget to use the ref parameter?":"Any additional parameter will be undefined."),e!=null&&e.defaultProps!=null&&console.error("forwardRef render functions do not support defaultProps. Did you accidentally pass a React component?");var r={$$typeof:w,render:e},s;return Object.defineProperty(r,"displayName",{enumerable:!1,configurable:!0,get:function(){return s},set:function(a){s=a,e.name||e.displayName||(Object.defineProperty(e,"name",{value:a}),e.displayName=a)}}),r},n.isValidElement=Y,n.lazy=function(e){e={_status:-1,_result:e};var r={$$typeof:B,_payload:e,_init:ae},s={name:"lazy",start:-1,end:-1,value:null,owner:null,debugStack:Error("react-stack-top-frame"),debugTask:console.createTask?console.createTask("lazy()"):null};return e._ioInfo=s,r._debugInfo=[{awaited:s}],r},n.memo=function(e,r){e==null&&console.error("memo: The first argument must be a component. Instead received: %s",e===null?"null":typeof e),r={$$typeof:S,type:e,compare:r===void 0?null:r};var s;return Object.defineProperty(r,"displayName",{enumerable:!1,configurable:!0,get:function(){return s},set:function(a){s=a,e.name||e.displayName||(Object.defineProperty(e,"name",{value:a}),e.displayName=a)}}),r},n.startTransition=function(e){var r=v.T,s={};s._updatedFibers=new Set,v.T=s;try{var a=e(),d=v.S;d!==null&&d(s,a),typeof a=="object"&&a!==null&&typeof a.then=="function"&&(v.asyncTransitions++,a.then(ee,ee),a.then(M,nt))}catch(g){nt(g)}finally{r===null&&s._updatedFibers&&(e=s._updatedFibers.size,s._updatedFibers.clear(),10<e&&console.warn("Detected a large number of updates inside startTransition. If this is due to a subscription please re-write it to use React provided hooks. Otherwise concurrent mode guarantees are off the table.")),r!==null&&s.types!==null&&(r.types!==null&&r.types!==s.types&&console.error("We expected inner Transitions to have transferred the outer types set and that you cannot add to the outer Transition while inside the inner.This is a bug in React."),r.types=s.types),v.T=r}},n.unstable_useCacheRefresh=function(){return O().useCacheRefresh()},n.use=function(e){return O().use(e)},n.useActionState=function(e,r,s){return O().useActionState(e,r,s)},n.useCallback=function(e,r){return O().useCallback(e,r)},n.useContext=function(e){var r=O();return e.$$typeof===f&&console.error("Calling useContext(Context.Consumer) is not supported and will cause bugs. Did you mean to call useContext(Context) instead?"),r.useContext(e)},n.useDebugValue=function(e,r){return O().useDebugValue(e,r)},n.useDeferredValue=function(e,r){return O().useDeferredValue(e,r)},n.useEffect=function(e,r){return e==null&&console.warn("React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?"),O().useEffect(e,r)},n.useEffectEvent=function(e){return O().useEffectEvent(e)},n.useId=function(){return O().useId()},n.useImperativeHandle=function(e,r,s){return O().useImperativeHandle(e,r,s)},n.useInsertionEffect=function(e,r){return e==null&&console.warn("React Hook useInsertionEffect requires an effect callback. Did you forget to pass a callback to the hook?"),O().useInsertionEffect(e,r)},n.useLayoutEffect=function(e,r){return e==null&&console.warn("React Hook useLayoutEffect requires an effect callback. Did you forget to pass a callback to the hook?"),O().useLayoutEffect(e,r)},n.useMemo=function(e,r){return O().useMemo(e,r)},n.useOptimistic=function(e,r){return O().useOptimistic(e,r)},n.useReducer=function(e,r,s){return O().useReducer(e,r,s)},n.useRef=function(e){return O().useRef(e)},n.useState=function(e){return O().useState(e)},n.useSyncExternalStore=function(e,r,s){return O().useSyncExternalStore(e,r,s)},n.useTransition=function(){return O().useTransition()},n.version="19.2.0",typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())})()})(le,le.exports)),le.exports}var De;function Ue(){return De||(De=1,process.env.NODE_ENV==="production"?me.exports=mt():me.exports=yt()),me.exports}var $=Ue();const ne={theMap:{},theList:[]},Et=u=>{const{myClass:n}=u;if(ne.theMap[n]){console.info("regsterThunk: already init:",n);return}const i={myClass:n,nodes:{}},l=()=>{},p={current:i},_=$.createContext({refClassState:p,setClassState:l});ne.theMap[n]={context:_,refClassState:p};const T=Object.keys(ne.theMap);T.sort(),ne.theList=T,console.info("registerThunk: done:",n)},Ie=u=>(n,i)=>{const l=i(),{nodes:{[u]:p}}=l;p&&n(ht(u))},Le="@chhsiao1981/use-thunk/REMOVE",ht=u=>({myID:u,type:Le}),vt=(u,n)=>{const{myID:i}=n;if(!u.nodes[i])return u;const p=Object.keys(u.nodes).filter(T=>T!==i).reduce((T,k)=>(T[k]=u.nodes[k],T),{}),_=Object.assign({},u,{nodes:p});return _.root===i&&(_.root=null),_},Ye="@chhsiao1981/use-thunk/SET_DATA",He=(u,n)=>({myID:u,type:Ye,data:n}),gt=(u,n)=>{const{myID:i,data:l}=n,p=u.nodes[i];if(!p)return u;const _=Object.assign({},p.state,l),T=Object.assign({},p,{state:_}),k=Object.assign({},u.nodes,{[i]:T});return Object.assign({},u,{nodes:k})},Rt=u=>{const n=u.root;return n&&u.nodes[n]||null},Tt=u=>u.root??"",wt=u=>{const n=u.root;if(!n)return null;const i=u.nodes[n];return i?i.state:null},bt=(u,n)=>n?u.nodes[n]||null:Rt(u),Ot=(u,n)=>{if(!n)return wt(u);const i=u.nodes[n];return i?i.state:null};var ye={exports:{}},de={};/**
|
|
30
|
+
* @license React
|
|
31
|
+
* react-jsx-runtime.production.js
|
|
32
|
+
*
|
|
33
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
34
|
+
*
|
|
35
|
+
* This source code is licensed under the MIT license found in the
|
|
36
|
+
* LICENSE file in the root directory of this source tree.
|
|
37
|
+
*/var xe;function Ct(){if(xe)return de;xe=1;var u=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function i(l,p,_){var T=null;if(_!==void 0&&(T=""+_),p.key!==void 0&&(T=""+p.key),"key"in p){_={};for(var k in p)k!=="key"&&(_[k]=p[k])}else _=p;return p=_.ref,{$$typeof:u,type:l,key:T,ref:p!==void 0?p:null,props:_}}return de.Fragment=n,de.jsx=i,de.jsxs=i,de}var pe={};/**
|
|
38
|
+
* @license React
|
|
39
|
+
* react-jsx-runtime.development.js
|
|
40
|
+
*
|
|
41
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
42
|
+
*
|
|
43
|
+
* This source code is licensed under the MIT license found in the
|
|
44
|
+
* LICENSE file in the root directory of this source tree.
|
|
45
|
+
*/var qe;function kt(){return qe||(qe=1,process.env.NODE_ENV!=="production"&&(function(){function u(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===ae?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case X:return"Fragment";case K:return"Profiler";case W:return"StrictMode";case se:return"Suspense";case b:return"SuspenseList";case J:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case oe:return"Portal";case Z:return t.displayName||"Context";case ue:return(t._context.displayName||"Context")+".Consumer";case Y:var o=t.render;return t=t.displayName,t||(t=o.displayName||o.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case ie:return o=t.displayName||null,o!==null?o:u(t.type)||"Memo";case U:o=t._payload,t=t._init;try{return u(t(o))}catch{}}return null}function n(t){return""+t}function i(t){try{n(t);var o=!1}catch{o=!0}if(o){o=console;var c=o.error,f=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return c.call(o,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",f),n(t)}}function l(t){if(t===X)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===U)return"<...>";try{var o=u(t);return o?"<"+o+">":"<...>"}catch{return"<...>"}}function p(){var t=O.A;return t===null?null:t.getOwner()}function _(){return Error("react-stack-top-frame")}function T(t){if(ee.call(t,"key")){var o=Object.getOwnPropertyDescriptor(t,"key").get;if(o&&o.isReactWarning)return!1}return t.key!==void 0}function k(t,o){function c(){I||(I=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",o))}c.isReactWarning=!0,Object.defineProperty(t,"key",{get:c,configurable:!0})}function M(){var t=u(this.type);return x[t]||(x[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function N(t,o,c,f,h,w){var m=c.ref;return t={$$typeof:Q,type:t,key:o,props:c,_owner:f},(m!==void 0?m:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:M}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:h}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:w}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function D(t,o,c,f,h,w){var m=o.children;if(m!==void 0)if(f)if(z(m)){for(f=0;f<m.length;f++)q(m[f]);Object.freeze&&Object.freeze(m)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else q(m);if(ee.call(o,"key")){m=u(t);var j=Object.keys(o).filter(function(B){return B!=="key"});f=0<j.length?"{key: someKey, "+j.join(": ..., ")+": ...}":"{key: someKey}",ce[m+f]||(j=0<j.length?"{"+j.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
46
|
+
let props = %s;
|
|
47
|
+
<%s {...props} />
|
|
48
|
+
React keys must be passed directly to JSX without using spread:
|
|
49
|
+
let props = %s;
|
|
50
|
+
<%s key={someKey} {...props} />`,f,m,j,m),ce[m+f]=!0)}if(m=null,c!==void 0&&(i(c),m=""+c),T(o)&&(i(o.key),m=""+o.key),"key"in o){c={};for(var S in o)S!=="key"&&(c[S]=o[S])}else c=o;return m&&k(c,typeof t=="function"?t.displayName||t.name||"Unknown":t),N(t,m,c,p(),h,w)}function q(t){V(t)?t._store&&(t._store.validated=1):typeof t=="object"&&t!==null&&t.$$typeof===U&&(t._payload.status==="fulfilled"?V(t._payload.value)&&t._payload.value._store&&(t._payload.value._store.validated=1):t._store&&(t._store.validated=1))}function V(t){return typeof t=="object"&&t!==null&&t.$$typeof===Q}var G=Ue(),Q=Symbol.for("react.transitional.element"),oe=Symbol.for("react.portal"),X=Symbol.for("react.fragment"),W=Symbol.for("react.strict_mode"),K=Symbol.for("react.profiler"),ue=Symbol.for("react.consumer"),Z=Symbol.for("react.context"),Y=Symbol.for("react.forward_ref"),se=Symbol.for("react.suspense"),b=Symbol.for("react.suspense_list"),ie=Symbol.for("react.memo"),U=Symbol.for("react.lazy"),J=Symbol.for("react.activity"),ae=Symbol.for("react.client.reference"),O=G.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ee=Object.prototype.hasOwnProperty,z=Array.isArray,H=console.createTask?console.createTask:function(){return null};G={react_stack_bottom_frame:function(t){return t()}};var I,x={},te=G.react_stack_bottom_frame.bind(G,_)(),F=H(l(_)),ce={};pe.Fragment=X,pe.jsx=function(t,o,c){var f=1e4>O.recentlyCreatedOwnerStacks++;return D(t,o,c,!1,f?Error("react-stack-top-frame"):te,f?H(l(t)):F)},pe.jsxs=function(t,o,c){var f=1e4>O.recentlyCreatedOwnerStacks++;return D(t,o,c,!0,f?Error("react-stack-top-frame"):te,f?H(l(t)):F)}})()),pe}var We;function St(){return We||(We=1,process.env.NODE_ENV==="production"?ye.exports=Ct():ye.exports=kt()),ye.exports}var At=St();const ze=u=>{let{classes:n,children:i}=u;if(n||(n=ne.theList),n.length===0)return i;const l=n[0],{context:p,refClassState:_}=ne.theMap[l],[T,k]=$.useState({myClass:l,nodes:{}});_.current=T;const M={refClassState:_,setClassState:k},N=n.length===1?i:ze({classes:n.slice(1),children:i});return At.jsx(p,{value:M,children:N})},jt=()=>({[Pe]:_t,[Ye]:gt,[Le]:vt,[Ae]:dt}),Pt=u=>(n,i)=>{if(!i)return n;const l=jt();return l!=null&&l[i.type]?l[i.type](n,i):n},$e={init:je,setData:He,remove:Ie},Nt=(u,n,i)=>(Object.keys(u).filter(l=>typeof u[l]=="function").reduce((l,p)=>{if(l[p])return l;const _=u[p];return l[p]=(...T)=>n(_(...T)),l},i),Object.keys($e).reduce((l,p)=>{if(l[p])return l;const _=$e[p];return l[p]=(...T)=>n(_(...T)),l},i),i),Mt=(u,n)=>{const{context:i}=ne.theMap[n],{refClassState:l,setClassState:p}=$.useContext(i),_=$.useCallback(()=>l.current,[l]),T=$.useCallback(N=>{l.current=N,p(N)},[l,p]),k=$.useCallback(N=>{const D=_();return u(D,N)},[u,_]),M=$.useCallback(N=>{if(typeof N=="function"){N(M,_);return}const D=k(N);T(D)},[_,T,k]);return[l.current,M]},Dt={},Ut=u=>{const{myClass:n}=u,i=Dt,l=!i[n];l&&(i[n]={});const p=i[n],_=$.useMemo(()=>u.default??Pt(),[]),[T,k]=Mt(_,n),M=$.useMemo(()=>[T,p],[T,p]);return l&&Nt(u,k,p),M};P.ThunkContext=ze,P.genUUID=ke,P.getNode=bt,P.getRootID=Tt,P.getState=Ot,P.init=je,P.registerThunk=Et,P.remove=Ie,P.setData=He,P.useThunk=Ut,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chhsiao1981/use-thunk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A framework easily using useThunk to manage the data-state.",
|
|
6
6
|
"homepage": "https://github.com/chhsiao1981/use-thunk",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"test": "vitest run",
|
|
33
33
|
"types": "tsc -b",
|
|
34
34
|
"coverage": "vitest run --coverage --reporter=junit --outputFile=test-report.junit.xml",
|
|
35
|
-
"tsd": "npx -p typescript tsc src/*.ts --declaration --allowJs --emitDeclarationOnly --strict --outDir types"
|
|
35
|
+
"tsd": "npx -p typescript tsc src/*.ts --declaration --allowJs --emitDeclarationOnly --strict --jsx react-jsx --outDir types"
|
|
36
36
|
},
|
|
37
37
|
"license": "MIT",
|
|
38
38
|
"devDependencies": {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ReactNode, useState } from 'react'
|
|
2
|
+
import type { ClassState } from './stateTypes'
|
|
3
|
+
import { THUNK_CONTEXT_MAP } from './thunkContextMap'
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
classes?: string[]
|
|
7
|
+
children?: ReactNode
|
|
8
|
+
}
|
|
9
|
+
const ThunkContext = (props: Props) => {
|
|
10
|
+
let { classes, children } = props
|
|
11
|
+
if (!classes) {
|
|
12
|
+
classes = THUNK_CONTEXT_MAP.theList
|
|
13
|
+
}
|
|
14
|
+
if (classes.length === 0) {
|
|
15
|
+
return children
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const theClass = classes[0]
|
|
19
|
+
|
|
20
|
+
const { context: Context_m, refClassState } = THUNK_CONTEXT_MAP.theMap[theClass]
|
|
21
|
+
|
|
22
|
+
// biome-ignore lint/correctness/useHookAtTopLevel: the order is fixed.
|
|
23
|
+
// biome-ignore lint/suspicious/noExplicitAny: This generalized state can be any type.
|
|
24
|
+
const [classState, setClassState] = useState<ClassState<any>>({ myClass: theClass, nodes: {} })
|
|
25
|
+
refClassState.current = classState
|
|
26
|
+
const value = { refClassState, setClassState }
|
|
27
|
+
|
|
28
|
+
const theChildren =
|
|
29
|
+
classes.length === 1 ? children : ThunkContext({ classes: classes.slice(1), children })
|
|
30
|
+
|
|
31
|
+
return <Context_m value={value}>{theChildren}</Context_m>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default ThunkContext
|
package/src/dispatchFuncMap.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { ActionFunc, BaseAction } from './action'
|
|
1
2
|
import type { State } from './stateTypes'
|
|
2
|
-
import type { ThunkModuleFunc } from './thunk'
|
|
3
|
-
import type
|
|
3
|
+
import type { ThunkModule, ThunkModuleFunc } from './thunk'
|
|
4
|
+
import { DEFAULT_THUNK_MODULE_FUNC_MAP, type DefaultThunkModuleFuncMap } from './thunkModuleFuncMap'
|
|
5
|
+
import type { Thunk as rThunk } from './useThunkReducer'
|
|
4
6
|
|
|
5
7
|
// biome-ignore lint/suspicious/noExplicitAny: unknown requires same type in list, use any for possible different types.
|
|
6
8
|
type VoidReturnType<T extends (...params: any[]) => unknown> = (...params: Parameters<T>) => void
|
|
@@ -17,6 +19,48 @@ export interface DispatchFuncMapByClassMap<S extends State, T extends ThunkModul
|
|
|
17
19
|
[className: string]: DispatchFuncMap<S, T>
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
// biome-ignore lint/suspicious/noExplicitAny: dispatch func map by class map can be any.
|
|
23
|
+
export const DISPATCH_FUNC_MAP_BY_CLASS_MAP: DispatchFuncMapByClassMap<any, any> = {}
|
|
24
|
+
|
|
25
|
+
export const constructDispatchMap = <
|
|
26
|
+
S extends State,
|
|
27
|
+
T extends ThunkModuleFunc<S>,
|
|
28
|
+
A extends BaseAction,
|
|
29
|
+
>(
|
|
30
|
+
theDo: ThunkModule<S, T>,
|
|
31
|
+
dispatch: (action: A | rThunk<S, A>) => void,
|
|
32
|
+
dispatchMap: DispatchFuncMap<S, T>,
|
|
33
|
+
) => {
|
|
34
|
+
Object.keys(theDo)
|
|
35
|
+
// default and myClass are reserved words.
|
|
36
|
+
// functions starting reduce are included in default and not exported.
|
|
37
|
+
.filter((each) => typeof theDo[each] === 'function')
|
|
38
|
+
.reduce((val, eachAction) => {
|
|
39
|
+
if (val[eachAction]) {
|
|
40
|
+
return val
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const action: ActionFunc<S> = theDo[eachAction]
|
|
44
|
+
|
|
45
|
+
// @ts-expect-error eachAction is in DispatchFuncMap<S, R>
|
|
46
|
+
// biome-ignore lint/suspicious/noExplicitAny: action parameters can be any types.
|
|
47
|
+
val[eachAction] = (...params: any[]) => dispatch(action(...params))
|
|
48
|
+
return val
|
|
49
|
+
}, dispatchMap)
|
|
50
|
+
|
|
51
|
+
Object.keys(DEFAULT_THUNK_MODULE_FUNC_MAP).reduce((val, eachAction) => {
|
|
52
|
+
if (val[eachAction]) {
|
|
53
|
+
return val
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// @ts-expect-error DEFAULT_REDUCER_MODULE_FUNCS are all ActionFunc<S>
|
|
57
|
+
const action: ActionFunc<S> = DEFAULT_THUNK_MODULE_FUNC_MAP[eachAction]
|
|
58
|
+
|
|
59
|
+
// @ts-expect-error eachAction is in DispatchFuncMap<S, R>
|
|
60
|
+
// biome-ignore lint/suspicious/noExplicitAny: action parameters can be any types.
|
|
61
|
+
val[eachAction] = (...params: any[]) => dispatch(action(...params))
|
|
62
|
+
return val
|
|
63
|
+
}, dispatchMap)
|
|
64
|
+
|
|
65
|
+
return dispatchMap
|
|
22
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import type { GetClassState, Thunk } from './action'
|
|
2
|
-
import { addChild } from './addChild'
|
|
3
|
-
import { addLink } from './addLink'
|
|
4
|
-
import type { AddRelationAction } from './addRelation'
|
|
5
2
|
import type { Dispatch } from './dispatch'
|
|
6
3
|
import type { DispatchFuncMap } from './dispatchFuncMap'
|
|
7
4
|
import { genUUID } from './genUUID'
|
|
8
|
-
import { getChildID, getChildIDs, getLinkID, getLinkIDs } from './getRelation'
|
|
9
5
|
import { type InitParams, init } from './init'
|
|
6
|
+
import registerThunk from './registerThunk'
|
|
10
7
|
import { remove } from './remove'
|
|
11
|
-
import { removeChild } from './removeChild'
|
|
12
|
-
import { removeLink } from './removeLink'
|
|
13
|
-
import type { RemoveRelationAction } from './removeRelation'
|
|
14
8
|
import { setData } from './setData'
|
|
15
9
|
import { getNode, getRootID, getState } from './states'
|
|
16
10
|
import type { ClassState, NodeMeta, NodeState, NodeStateMap, State } from './stateTypes'
|
|
11
|
+
import ThunkContext from './ThunkContext'
|
|
17
12
|
import type { ThunkModule, ThunkModuleToFunc } from './thunk'
|
|
18
13
|
import useThunk, { type UseThunk } from './useThunk'
|
|
19
14
|
|
|
20
15
|
export {
|
|
16
|
+
registerThunk,
|
|
21
17
|
useThunk,
|
|
18
|
+
ThunkContext,
|
|
22
19
|
type UseThunk,
|
|
23
|
-
// StateType, // XXX for global state
|
|
24
20
|
type State,
|
|
25
21
|
type NodeState,
|
|
26
22
|
type NodeMeta,
|
|
@@ -42,20 +38,10 @@ export {
|
|
|
42
38
|
getRootID,
|
|
43
39
|
getNode,
|
|
44
40
|
getState,
|
|
45
|
-
getChildIDs,
|
|
46
|
-
getChildID,
|
|
47
|
-
getLinkIDs,
|
|
48
|
-
getLinkID,
|
|
49
41
|
init,
|
|
50
42
|
type InitParams,
|
|
51
43
|
setData,
|
|
52
44
|
remove,
|
|
53
|
-
addChild,
|
|
54
|
-
removeChild,
|
|
55
|
-
addLink,
|
|
56
|
-
removeLink,
|
|
57
|
-
type AddRelationAction,
|
|
58
|
-
type RemoveRelationAction,
|
|
59
45
|
// type DefaultThunkModuleFuncMap as DefaultReducerModuleFuncMap, // XXX deemphasize default
|
|
60
46
|
// type ReduceMap, // XXX deemphasize reducer
|
|
61
47
|
// createReducer, // XXX deemphasize reducer
|
package/src/init.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BaseAction, Thunk } from './action'
|
|
2
2
|
import { genUUID } from './genUUID'
|
|
3
3
|
import { setRoot } from './setRoot'
|
|
4
|
-
import {
|
|
4
|
+
import type { ClassState, NodeState, NodeStateMap, State } from './stateTypes'
|
|
5
5
|
|
|
6
6
|
// InitParams
|
|
7
7
|
export interface InitParams<S extends State> {
|
|
@@ -18,16 +18,12 @@ export const init = <S extends State>(params: InitParams<S>, myuuidv4?: () => st
|
|
|
18
18
|
return (dispatch, getClassState) => {
|
|
19
19
|
const myID = params.myID ?? genUUID(myuuidv4)
|
|
20
20
|
|
|
21
|
-
const {
|
|
22
|
-
dispatch(initCore(myID, state
|
|
21
|
+
const { state } = params
|
|
22
|
+
dispatch(initCore(myID, state))
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
const { myClass, doMe, root } = getClassState()
|
|
24
|
+
const { root } = getClassState()
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
if (parentID && doParent) {
|
|
29
|
-
doParent.addChild(parentID, { id: myID, theClass: myClass, do: doMe })
|
|
30
|
-
} else if (!root) {
|
|
26
|
+
if (!root) {
|
|
31
27
|
dispatch(setRoot(myID))
|
|
32
28
|
}
|
|
33
29
|
}
|
|
@@ -43,38 +39,24 @@ interface InitAction<S extends State> extends BaseAction {
|
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
export const INIT = '@chhsiao1981/use-thunk/INIT'
|
|
46
|
-
const initCore = <S extends State>(
|
|
47
|
-
myID: string,
|
|
48
|
-
state: S,
|
|
49
|
-
parentID?: string,
|
|
50
|
-
// @ts-expect-error doParent can be any type
|
|
51
|
-
doParent?: DispatchFuncMap,
|
|
52
|
-
parentClass?: string,
|
|
53
|
-
): InitAction<S> => {
|
|
42
|
+
const initCore = <S extends State>(myID: string, state: S): InitAction<S> => {
|
|
54
43
|
return {
|
|
55
44
|
myID,
|
|
56
45
|
type: INIT,
|
|
57
|
-
parentID,
|
|
58
|
-
doParent,
|
|
59
|
-
parentClass,
|
|
60
|
-
|
|
61
46
|
state,
|
|
62
47
|
}
|
|
63
48
|
}
|
|
64
49
|
|
|
65
|
-
export const reduceInit = <S extends State>(
|
|
66
|
-
|
|
50
|
+
export const reduceInit = <S extends State>(
|
|
51
|
+
classState: ClassState<S>,
|
|
52
|
+
action: InitAction<S>,
|
|
53
|
+
): ClassState<S> => {
|
|
54
|
+
const { myID, state } = action
|
|
67
55
|
|
|
68
56
|
const myNode: NodeState<S> = {
|
|
69
57
|
id: myID,
|
|
70
|
-
state:
|
|
71
|
-
[Relation.CHILDREN]: {},
|
|
72
|
-
[Relation.LINKS]: {},
|
|
58
|
+
state: state,
|
|
73
59
|
}
|
|
74
|
-
if (parentID && doParent) {
|
|
75
|
-
myNode[PARENT] = { id: parentID, do: doParent, theClass: parentClass ?? '' }
|
|
76
|
-
}
|
|
77
|
-
|
|
78
60
|
const newNodes: NodeStateMap<S> = Object.assign({}, classState.nodes, { [myID]: myNode })
|
|
79
61
|
const newClassState: ClassState<S> = Object.assign({}, classState, { nodes: newNodes })
|
|
80
62
|
|
package/src/reduceMap.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { ADD_CHILD, reduceAddChild } from './addChild'
|
|
2
|
-
import { ADD_LINK, reduceAddLink } from './addLink'
|
|
3
1
|
import { INIT, reduceInit } from './init'
|
|
4
2
|
import type { ReduceFunc } from './reducer'
|
|
5
3
|
import { REMOVE, reduceRemove } from './remove'
|
|
6
|
-
import { REMOVE_CHILD, reduceRemoveChild } from './removeChild'
|
|
7
|
-
import { REMOVE_LINK, reduceRemoveLink } from './removeLink'
|
|
8
4
|
import { reduceSetData, SET_DATA } from './setData'
|
|
9
5
|
import { reduceSetRoot, SET_ROOT } from './setRoot'
|
|
10
6
|
import type { State } from './stateTypes'
|
|
@@ -20,16 +16,6 @@ export const DEFAULT_REDUCE_MAP: <S extends State>() => ReduceMap<S> = () => ({
|
|
|
20
16
|
[SET_DATA]: reduceSetData,
|
|
21
17
|
[REMOVE]: reduceRemove,
|
|
22
18
|
|
|
23
|
-
// @ts-expect-error baseAction in ReduceMap
|
|
24
|
-
[ADD_CHILD]: reduceAddChild,
|
|
25
|
-
// @ts-expect-error baseAction in ReduceMap
|
|
26
|
-
[REMOVE_CHILD]: reduceRemoveChild,
|
|
27
|
-
|
|
28
|
-
// @ts-expect-error baseAction in ReduceMap
|
|
29
|
-
[ADD_LINK]: reduceAddLink,
|
|
30
|
-
// @ts-expect-error baseAction in ReduceMap
|
|
31
|
-
[REMOVE_LINK]: reduceRemoveLink,
|
|
32
|
-
|
|
33
19
|
// setRoot.
|
|
34
20
|
// Typically we don't need this in programming.
|
|
35
21
|
// The root is automatically determined if root is not set.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createContext, type Dispatch, type SetStateAction } from 'react'
|
|
2
|
+
import type { ClassState, State } from './stateTypes'
|
|
3
|
+
import type { ThunkModule, ThunkModuleFunc } from './thunk'
|
|
4
|
+
import { THUNK_CONTEXT_MAP } from './thunkContextMap'
|
|
5
|
+
|
|
6
|
+
export default <S extends State, R extends ThunkModuleFunc<S>>(theDo: ThunkModule<S, R>) => {
|
|
7
|
+
const { myClass } = theDo
|
|
8
|
+
|
|
9
|
+
if (THUNK_CONTEXT_MAP.theMap[myClass]) {
|
|
10
|
+
// already init
|
|
11
|
+
console.info('regsterThunk: already init:', myClass)
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const classState: ClassState<S> = {
|
|
16
|
+
myClass,
|
|
17
|
+
nodes: {},
|
|
18
|
+
}
|
|
19
|
+
const setClassState: Dispatch<SetStateAction<ClassState<S>>> = () => {}
|
|
20
|
+
const refClassState = { current: classState }
|
|
21
|
+
const context = createContext({
|
|
22
|
+
refClassState,
|
|
23
|
+
setClassState,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
THUNK_CONTEXT_MAP.theMap[myClass] = {
|
|
27
|
+
context,
|
|
28
|
+
refClassState,
|
|
29
|
+
}
|
|
30
|
+
const theList = Object.keys(THUNK_CONTEXT_MAP.theMap)
|
|
31
|
+
theList.sort()
|
|
32
|
+
THUNK_CONTEXT_MAP.theList = theList
|
|
33
|
+
|
|
34
|
+
console.info('registerThunk: done:', myClass)
|
|
35
|
+
}
|
package/src/remove.ts
CHANGED
|
@@ -1,45 +1,16 @@
|
|
|
1
1
|
import type { BaseAction, Thunk } from './action'
|
|
2
|
-
import {
|
|
3
|
-
import { removeLink } from './removeLink'
|
|
4
|
-
import { type ClassState, type NodeStateMap, PARENT, Relation, type State } from './stateTypes'
|
|
2
|
+
import type { ClassState, NodeStateMap, State } from './stateTypes'
|
|
5
3
|
|
|
6
|
-
export const remove = <S extends State>(myID: string
|
|
4
|
+
export const remove = <S extends State>(myID: string): Thunk<S> => {
|
|
7
5
|
return (dispatch, getClassState) => {
|
|
8
6
|
const state = getClassState()
|
|
9
7
|
const {
|
|
10
|
-
myClass,
|
|
11
8
|
nodes: { [myID]: me },
|
|
12
9
|
} = state
|
|
13
10
|
if (!me) {
|
|
14
11
|
return
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
// parent removes me
|
|
18
|
-
const parent = me[PARENT]
|
|
19
|
-
if (!isFromParent && parent) {
|
|
20
|
-
const { id: parentID, do: doParent } = parent
|
|
21
|
-
if (parentID) {
|
|
22
|
-
doParent.removeChild(parentID, myID, myClass, true)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// remove children
|
|
27
|
-
const children = me[Relation.CHILDREN]
|
|
28
|
-
if (children) {
|
|
29
|
-
const realChildren = children
|
|
30
|
-
Object.keys(realChildren).map((eachClass) => {
|
|
31
|
-
const child = realChildren[eachClass]
|
|
32
|
-
child.list.map((eachID) => dispatch(removeChild(myID, eachID, eachClass, false)))
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// remove links
|
|
37
|
-
const links = me[Relation.LINKS] ?? {}
|
|
38
|
-
Object.keys(links).map((eachClass) => {
|
|
39
|
-
const link = links[eachClass]
|
|
40
|
-
link.list.map((eachID) => dispatch(removeLink(myID, eachID, eachClass, false)))
|
|
41
|
-
})
|
|
42
|
-
|
|
43
14
|
// remove me from myClass list
|
|
44
15
|
dispatch(removeCore(myID))
|
|
45
16
|
}
|
|
@@ -51,7 +22,10 @@ const removeCore = (myID: string): BaseAction => ({
|
|
|
51
22
|
type: REMOVE,
|
|
52
23
|
})
|
|
53
24
|
|
|
54
|
-
export const reduceRemove = <S extends State>(
|
|
25
|
+
export const reduceRemove = <S extends State>(
|
|
26
|
+
classState: ClassState<S>,
|
|
27
|
+
action: BaseAction,
|
|
28
|
+
): ClassState<S> => {
|
|
55
29
|
const { myID } = action
|
|
56
30
|
|
|
57
31
|
const myNode = classState.nodes[myID]
|
package/src/setData.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { BaseAction } from './action'
|
|
|
2
2
|
import type { ClassState, State } from './stateTypes'
|
|
3
3
|
|
|
4
4
|
export const SET_DATA = '@chhsiao1981/use-thunk/SET_DATA'
|
|
5
|
-
export const setData = <S extends State>(myID: string, data: S): BaseAction => ({
|
|
5
|
+
export const setData = <S extends State>(myID: string, data: Partial<S>): BaseAction => ({
|
|
6
6
|
myID,
|
|
7
7
|
type: SET_DATA,
|
|
8
8
|
data,
|
package/src/setRoot.ts
CHANGED
|
@@ -7,7 +7,10 @@ export const setRoot = (myID: string): BaseAction => ({
|
|
|
7
7
|
type: SET_ROOT,
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
-
export const reduceSetRoot = <S extends State>(
|
|
10
|
+
export const reduceSetRoot = <S extends State>(
|
|
11
|
+
classState: ClassState<S>,
|
|
12
|
+
action: BaseAction,
|
|
13
|
+
): ClassState<S> => {
|
|
11
14
|
const { myID } = action
|
|
12
15
|
|
|
13
16
|
return Object.assign({}, classState, { root: myID })
|
package/src/stateTypes.ts
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
export enum StateType {
|
|
2
|
-
// SHARED = 'shared',
|
|
3
|
-
LOCAL = 'local',
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export enum Relation {
|
|
7
|
-
CHILDREN = '_children',
|
|
8
|
-
LINKS = '_links',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// XXX PARENT is considered as a special relation
|
|
12
|
-
// and is not part of the enum Relation.
|
|
13
|
-
// The relation-ops does not apply to PARENT.
|
|
14
|
-
export const PARENT = '_parent'
|
|
15
|
-
|
|
16
1
|
//State
|
|
17
2
|
export interface State {
|
|
18
3
|
[key: string]: unknown
|
|
@@ -22,20 +7,6 @@ export interface State {
|
|
|
22
7
|
export type NodeState<S extends State> = {
|
|
23
8
|
id: string
|
|
24
9
|
state: S
|
|
25
|
-
[Relation.CHILDREN]?: NodeStateRelationMap | null
|
|
26
|
-
[PARENT]?: NodeMeta | null
|
|
27
|
-
[Relation.LINKS]?: NodeStateRelationMap | null
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// NodeStateRelation
|
|
31
|
-
type NodeStateRelationMap = {
|
|
32
|
-
[relationClass: string]: NodeStateRelation
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type NodeStateRelation = {
|
|
36
|
-
list: string[]
|
|
37
|
-
// @ts-expect-error do can be any type.
|
|
38
|
-
do: DispatchFuncMap
|
|
39
10
|
}
|
|
40
11
|
|
|
41
12
|
export type NodeStateMap<S extends State> = {
|
package/src/states.ts
CHANGED
|
@@ -24,7 +24,10 @@ const getRoot = <S extends State>(classState: ClassState<S>): S | null => {
|
|
|
24
24
|
return me.state
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export const getNode = <S extends State>(
|
|
27
|
+
export const getNode = <S extends State>(
|
|
28
|
+
classState: ClassState<S>,
|
|
29
|
+
myID?: string,
|
|
30
|
+
): NodeState<S> | null => {
|
|
28
31
|
if (!myID) {
|
|
29
32
|
return getRootNode(classState)
|
|
30
33
|
}
|
package/src/thunk.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface ThunkModuleFunc<S extends State> {
|
|
|
10
10
|
export type ThunkModule<S extends State, T extends ThunkModuleFunc<S>> = {
|
|
11
11
|
myClass: string
|
|
12
12
|
default?: Reducer<S>
|
|
13
|
-
defaultState
|
|
13
|
+
defaultState: S
|
|
14
14
|
} & T
|
|
15
15
|
|
|
16
16
|
export type ThunkModuleToFunc<T> = Omit<T, 'myClass' | 'default' | 'defaultState'>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Context as rContext } from 'react'
|
|
2
|
+
import type { ClassState } from './stateTypes'
|
|
3
|
+
import type { Context } from './thunkContextTypes'
|
|
4
|
+
|
|
5
|
+
export type ThunkContextMap = {
|
|
6
|
+
theMap: {
|
|
7
|
+
[classname: string]: {
|
|
8
|
+
// biome-ignore lint/suspicious/noExplicitAny: ThunkContextMap can be any type
|
|
9
|
+
context: rContext<Context<any>>
|
|
10
|
+
|
|
11
|
+
// INFO We need to use refClassState to sync all the classState in all ops.
|
|
12
|
+
// biome-ignore lint/suspicious/noExplicitAny: ThunkContextMap can be any type
|
|
13
|
+
refClassState: { current: ClassState<any> }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
theList: string[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const THUNK_CONTEXT_MAP: ThunkContextMap = {
|
|
20
|
+
theMap: {},
|
|
21
|
+
theList: [],
|
|
22
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Dispatch, SetStateAction } from 'react'
|
|
2
|
+
import type { ClassState, State } from './stateTypes'
|
|
3
|
+
|
|
4
|
+
export type Context<S extends State> = {
|
|
5
|
+
// INFO: we use refClassState to reference across all the useThunk of the same class in different ops.
|
|
6
|
+
refClassState: { current: ClassState<S> }
|
|
7
|
+
setClassState: Dispatch<SetStateAction<ClassState<S>>>
|
|
8
|
+
}
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import { addChild } from './addChild'
|
|
2
|
-
import { addLink } from './addLink'
|
|
3
1
|
import { init } from './init'
|
|
4
2
|
import { remove } from './remove'
|
|
5
|
-
import { removeChild } from './removeChild'
|
|
6
|
-
import { removeLink } from './removeLink'
|
|
7
3
|
import { setData } from './setData'
|
|
8
4
|
|
|
9
5
|
export const DEFAULT_THUNK_MODULE_FUNC_MAP = {
|
|
10
6
|
init,
|
|
11
7
|
setData,
|
|
12
8
|
remove,
|
|
13
|
-
|
|
14
|
-
addChild,
|
|
15
|
-
|
|
16
|
-
removeChild,
|
|
17
|
-
|
|
18
|
-
addLink,
|
|
19
|
-
removeLink,
|
|
20
9
|
}
|
|
21
10
|
|
|
22
11
|
export type DefaultThunkModuleFuncMap = typeof DEFAULT_THUNK_MODULE_FUNC_MAP
|