solid-alive 0.2.2 → 0.2.5
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createComponent as e}from"solid-js/web";import{createStore 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,createComputed as a,createEffect as d,onCleanup as s}from"solid-js";var v=o({elements:{},symbolClose:Symbol("close"),info:{frozen:!1,cbOnOff:"off",currComponentId:""},setInfo:()=>{},insertElement:()=>{},onDeactivated:()=>{},onActivated:()=>{},removeAliveElements:()=>{},insertCacheCb:()=>{}});function c(o){let[i,l]=n(),a={frozen:!1,cbOnOff:"off",currComponentId:""},d=Symbol("close"),s=new Map,c=new Map,f={onActivated:{},onDeactivated:{}};var u=e=>{var n;if(Reflect.has(i,e)){var t=null===(n=i[e])||void 0===n?void 0:n.subIds;null==t||t.forEach((n=>n!==e&&u(n))),l({[e]:void 0})}},m=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=f[e];return(!o[n]||o[n]===t)&&(f[e][n]=t,!0)},b=(e,n)=>{var{cbOnOff:t,currComponentId:o}=a;if("on"===t&&o!==d&&n&&m(e)){var i={onActivated:s,onDeactivated:c}[e],l=i.get(o)||new Set;l.add(r([],n))&&i.set(o,l)}};return e(v.Provider,{value:{info:a,elements:i,symbolClose:d,setInfo:(e,n)=>{a[e]=n},onActivated:e=>{b("onActivated",e)},onDeactivated:e=>{b("onDeactivated",e)},insertElement:e=>{let n=e.id,t=Object.values(i).find((e=>{var t;return null===(t=e.subIds)||void 0===t?void 0:t.has(n)}));l([n],Object.assign(Object.assign(Object.assign({},i[n]),e),{fatherId:null==t?void 0:t.id}))},removeAliveElements:e=>{if(Array.isArray(e))for(const n of e)u(n);else if(!e)for(const e of Object.values(i))u(e.id)},insertCacheCb:e=>{let n=s.get(e),o=c.get(e);s.delete(e),c.delete(e),f.onActivated={},f.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 f=new Set([]);function u(e,n,t){return function(o){var{info:r,elements:c,symbolClose:u,setInfo:m,insertElement:b,insertCacheCb:A}=i(v);Reflect.has(c,n)||l((r=>{m("currComponentId",n),m("cbOnOff","on"),b({id:n,dispose:r,owner:null,element:e(o),subIds:Array.isArray(t)?new Set(t):null})}));var O=e=>{var n=c[e].fatherId;return n?O(n):e};return f.size&&!f.has(O(n))&&f.clear(),a((()=>{var e;!c[n].loaded&&(e=>{var n;let t=null===(n=c[e])||void 0===n?void 0:n.element;for(;"function"==typeof t;)t=t();return!!(t instanceof HTMLElement||Array.isArray(t))&&t})(n)&&(A(n),!(null===(e=c[n].subIds)||void 0===e?void 0:e.size)&&m("currComponentId",u))})),d((()=>{var e,t,o;r.frozen?!(null===(e=c[n].subIds)||void 0===e?void 0:e.size)&&m("frozen",!1):(null===(t=c[n])||void 0===t?void 0:t.loaded)&&(f.add(n),m("cbOnOff","off"),null===(o=c[n].onActivated)||void 0===o||o.forEach((e=>e())),m("cbOnOff","on"))})),s((()=>{var e,t;r.frozen||(m("cbOnOff","off"),null===(t=null===(e=c[n])||void 0===e?void 0:e.onDeactivated)||void 0===t||t.forEach((e=>e())),m("cbOnOff","on"))})),c[n].element}}function m(n){var t=u((()=>n.children),n.id,n.subIds);return e(t,{})}function b(){var{onActivated:e,onDeactivated:n,removeAliveElements:t,setInfo:o}=i(v);return{onActivated:e,onDeactivated:n,removeAliveElements:t,setInfo:o}}function A(e){var{onActivated:n}=b();n(e)}function O(e){var{onDeactivated:n}=b();n(e)}function h(){var{removeAliveElements:e,setInfo:n}=b();return{removeAliveElements:e,aliveFrozen:()=>n("frozen",!0)}}export{m as AliveComponent,c as AliveProvider,u as aliveTransfer,A as onActivated,O as onDeactivated,h as useAlive};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JSX } from 'solid-js';
|
|
2
2
|
/**
|
|
3
|
-
* @description Alive 组件用的
|
|
4
|
-
* @param { ()=> JSX.Element } Component
|
|
3
|
+
* @description Alive 组件用的 转换函数; aliveTransfer(Comp, ‘/home’)
|
|
4
|
+
* @param { ()=> JSX.Element } Component () => JSX.Element
|
|
5
5
|
* @param { string } id string,自己的id 值,一定要唯一
|
|
6
6
|
* @param { Array<string> } [subIds] [string,...], 子组件的 id值 可不传,这样默认销毁时不会去干掉子组件,
|
|
7
7
|
*/
|
package/dist/types/context.d.ts
CHANGED
package/dist/types/default.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ export interface ProveiderProps {
|
|
|
7
7
|
export interface NodeInfo {
|
|
8
8
|
id: string
|
|
9
9
|
loaded?: boolean
|
|
10
|
-
owner: any
|
|
11
|
-
props?:any
|
|
12
|
-
component?: ((props:any) => JSX.Element) | null
|
|
10
|
+
owner: any
|
|
11
|
+
props?: any
|
|
12
|
+
component?: ((props: any) => JSX.Element) | null
|
|
13
13
|
element?: JSX.Element | null
|
|
14
14
|
subIds?: Set<string> | null
|
|
15
15
|
dispose?: (() => void) | null
|
|
@@ -27,7 +27,9 @@ export interface StoreProps {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export interface IInfo {
|
|
30
|
-
frozen: boolean
|
|
30
|
+
frozen: boolean
|
|
31
|
+
cbOnOff: 'on' | 'off'
|
|
32
|
+
currComponentId: string | symbol
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export type TSetInfo = <T extends keyof IInfo>(key: T, value: IInfo[T]) => void
|
|
@@ -35,13 +37,13 @@ export type TSetInfo = <T extends keyof IInfo>(key: T, value: IInfo[T]) => void
|
|
|
35
37
|
export interface ContextProps {
|
|
36
38
|
elements: StoreProps
|
|
37
39
|
info: IInfo
|
|
40
|
+
symbolClose: symbol
|
|
38
41
|
setInfo: TSetInfo
|
|
39
42
|
insertElement: (d: NodeInfo) => void
|
|
40
43
|
onActivated: (cb: () => void) => void
|
|
41
44
|
onDeactivated: (cb: () => void) => void
|
|
42
45
|
removeAliveElements: (ids?: Array<IAliveElementIds>) => void
|
|
43
|
-
|
|
44
|
-
insertCacheCb: (id: string ) => void
|
|
46
|
+
insertCacheCb: (id: string) => void
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
interface IActive {
|
|
@@ -52,4 +54,4 @@ export interface IPrevCall {
|
|
|
52
54
|
onDeactivated: IActive
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
export type IAliveElementIds =
|
|
57
|
+
export type IAliveElementIds = string
|