solid-alive 0.1.9 → 0.2.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/dist/index.js +1 -1
- package/dist/types/default.d.ts +8 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createComponent as e}from"solid-js/web";import{createStore as n,produce as t}from"solid-js/store";import{createContext as o,on as r,useContext as
|
|
1
|
+
import{createComponent as e}from"solid-js/web";import{createStore as n,produce as t}from"solid-js/store";import{createContext as o,on as r,useContext as i,createRoot as l,createEffect as a,onCleanup as v}from"solid-js";var d=o({elements:{},info:{frozen:!1},setInfo:()=>{},insertElement:()=>{},onDeactivated:()=>{},onActivated:()=>{},removeAliveElement:()=>{},setCurrentComponentId:()=>{},insertCacheCb:()=>{}});function c(o){let[i,l]=n(),[a,v]=n({frozen:!0}),c="",s=new Map,f=new Map,u={onActivated:{},onDeactivated:{}};var m=e=>{var n;if(Reflect.has(i,e)){var t=null===(n=i[e])||void 0===n?void 0:n.children;null==t||t.forEach((n=>n!==e&&m(n))),l((n=>{var t,o;return n[e].onDeactivated=null,n[e].component=null,null===(o=(t=n[e]).dispose)||void 0===o||o.call(t),n[e].dispose=null,n[e].onActivated=null,n[e].onDeactivated=null,n[e].children=null,n[e]=null,delete n[e],n}))}},p=e=>{var{caller:n,path:t}=function(){var e=null,n=null;try{throw new Error}catch(l){var t=l.stack.split("\n"),o=t[0].includes("@")?5:6,r=t[o].trim(),i=r.includes("@")?r.split("@"):r.split(" ").slice(1);e=i[0],n=i[1]}return{caller:e,path:n}}(),o=u[e];return o[n]&&o[n]!==t?(console.warn(`[solid-alive]:检测到多个${e}函数 ${t}`),!1):(u[e][n]=t,!0)},h=(e,n)=>{if(!a.frozen&&n&&p(e)){var t={onActivated:s,onDeactivated:f}[e],o=t.get(c)||new Set;o.add(r([],n))&&t.set(c,o)}};return e(d.Provider,{value:{info:a,elements:i,setInfo:v,onActivated:e=>{h("onActivated",e)},onDeactivated:e=>{h("onDeactivated",e)},insertElement:e=>{let n=e.id;l([n],Object.assign(Object.assign({},i[n]),e))},removeAliveElement:e=>{if(null==e)for(const e of Object.values(i))m(e.id);else m(e)},setCurrentComponentId:e=>{c=e},insertCacheCb:e=>{let n=s.get(e),o=f.get(e);s.delete(e),f.delete(e),u.onActivated={},u.onDeactivated={},Reflect.has(i,e)&&l(t((t=>{t[e].onActivated=n,t[e].onDeactivated=o,t[e].loaded=!0})))}},get children(){return o.children}})}let s=new Set([]);function f(n,t,o){var{info:r,elements:c,setInfo:f,insertElement:u,setCurrentComponentId:m,insertCacheCb:p}=i(d);Reflect.has(c,t)||(f("frozen",!1),m(t),l((r=>{u({id:t,dispose:r,component:e(n,{}),children:Array.isArray(o)?new Set(o):null})})));var h=e=>{var n;if(c[e].isTop)return e;var t=null===(n=Object.values(c).find((n=>{var t;return null===(t=n.children)||void 0===t?void 0:t.has(e)})))||void 0===n?void 0:n.id;return t&&(t=h(t)),t||e};return s.has(h(t))||s.clear(),a((()=>{var e,n;if(f("frozen",!1),!s.has(t))if(c[t].loaded)s.add(t),f("frozen",!0),null===(e=c[t].onActivated)||void 0===e||e.forEach((e=>e())),f("frozen",!1);else{let e=null===(n=c[t])||void 0===n?void 0:n.component;for(;"function"==typeof e;)e=e();e instanceof HTMLElement&&p(t)}})),v((()=>{var e;r.frozen||(f("frozen",!0),null===(e=c[t].onDeactivated)||void 0===e||e.forEach((e=>e())),f("frozen",!1))})),c[t].component}function u(){var{onActivated:e,onDeactivated:n,removeAliveElement:t,setInfo:o}=i(d);return{onActivated:e,onDeactivated:n,removeAliveElement:t,setInfo:o}}function m(e){var{onActivated:n}=u();n(e)}function p(e){var{onDeactivated:n}=u();n(e)}function h(){var{removeAliveElement:e,setInfo:n}=u();return{removeAliveElement:e,aliveFrozen:()=>n("frozen",!0)}}export{c as AliveProvider,f as AliveTransfer,m as onActivated,p as onDeactivated,h as useAlive};
|
package/dist/types/default.d.ts
CHANGED
|
@@ -40,3 +40,11 @@ export interface ContextProps {
|
|
|
40
40
|
setCurrentComponentId: (id: string | symbol) => void
|
|
41
41
|
insertCacheCb: (id: string) => void
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
interface IActive {
|
|
45
|
+
[key:string]: string
|
|
46
|
+
}
|
|
47
|
+
export interface IPrevCall {
|
|
48
|
+
onActivated: IActive
|
|
49
|
+
onDeactivated: IActive
|
|
50
|
+
}
|