solid-alive 0.2.2 → 0.2.6

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 t,produce as n}from"solid-js/store";import{createContext as r,on as o,useContext as a,createRoot as i,createComputed as l,createEffect as s,onCleanup as d}from"solid-js";var v=r({elements:{},info:{frozen:!1},setInfo:()=>{},insertElement:()=>{},onDeactivated:()=>{},onActivated:()=>{},removeAliveElements:()=>{},setCurrentComponentId:()=>{},insertCacheCb:()=>{}});function c(r){let[a,i]=t(),[l,s]=t({frozen:!0}),d="",c=new Map,f=new Map,u={onActivated:{},onDeactivated:{}};var m=e=>{var t;if(Reflect.has(a,e)){var n=null===(t=a[e])||void 0===t?void 0:t.subIds;null==n||n.forEach((t=>t!==e&&m(t))),i((t=>{var n,r;return null===(r=(n=t[e]).dispose)||void 0===r||r.call(n),t[e]=null,delete t[e],t}))}},A=e=>{var{caller:t,path:n}=function(){var e=null,t=null;try{throw new Error}catch(i){var n=i.stack.split("\n"),r=n[0].includes("@")?5:6,o=n[r].trim(),a=o.includes("@")?o.split("@"):o.split(" ").slice(1);e=a[0],t=a[1]}return{caller:e,path:t}}(),r=u[e];return(!r[t]||r[t]===n)&&(u[e][t]=n,!0)},h=(e,t)=>{if(!l.frozen&&t&&A(e)){var n={onActivated:c,onDeactivated:f}[e],r=n.get(d)||new Set;r.add(o([],t))&&n.set(d,r)}};return e(v.Provider,{value:{info:l,elements:a,setInfo:s,onActivated:e=>{h("onActivated",e)},onDeactivated:e=>{h("onDeactivated",e)},insertElement:e=>{let t=e.id;var n=Object.values(a).find((e=>{var n;return null===(n=e.subIds)||void 0===n?void 0:n.has(t)}));i([t],Object.assign(Object.assign(Object.assign({},a[t]),e),{fatherId:null==n?void 0:n.id}))},removeAliveElements:e=>{if(Array.isArray(e))for(const t of e)m(t);else if(!e)for(const e of Object.values(a))m(e.id)},setCurrentComponentId:e=>{d=e},insertCacheCb:e=>{let t=c.get(e),r=f.get(e);c.delete(e),f.delete(e),u.onActivated={},u.onDeactivated={},Reflect.has(a,e)&&i(n((n=>{n[e].onActivated=t,n[e].onDeactivated=r,n[e].loaded=!0})))}},get children(){return r.children}})}let f=new Set([]);function u(e,t,n){return function(r){var{info:o,elements:c,setInfo:u,insertElement:m,setCurrentComponentId:A,insertCacheCb:h}=a(v);Reflect.has(c,t)||(u("frozen",!1),A(t),i((o=>{m({id:t,dispose:o,owner:null,element:e(r),subIds:Array.isArray(n)?new Set(n):null})})));var p=e=>{var t=c[e].fatherId;return t?p(t):e};return l((()=>{var e;if(c[t].loaded)return;let n=null===(e=c[t])||void 0===e?void 0:e.element;for(;"function"==typeof n;)n=n();(Array.isArray(n)||n instanceof HTMLElement)&&h(t)})),f.size&&!f.has(p(t))&&f.clear(),s((()=>{var e;u("frozen",!1),f.has(t)||c[t].loaded&&(f.add(t),u("frozen",!0),null===(e=c[t].onActivated)||void 0===e||e.forEach((e=>e())),u("frozen",!1))})),d((()=>{var e;o.frozen||(u("frozen",!0),null===(e=c[t].onDeactivated)||void 0===e||e.forEach((e=>e())))})),c[t].element}}function m(t){var n=u((()=>t.children),t.id,t.subIds);return e(n,{})}function A(){var{onActivated:e,onDeactivated:t,removeAliveElements:n,setInfo:r}=a(v);return{onActivated:e,onDeactivated:t,removeAliveElements:n,setInfo:r}}function h(e){var{onActivated:t}=A();t(e)}function p(e){var{onDeactivated:t}=A();t(e)}function I(){var{removeAliveElements:e,setInfo:t}=A();return{removeAliveElements:e,aliveFrozen:()=>t("frozen",!0)}}export{m as AliveComponent,c as AliveProvider,u as aliveTransfer,h as onActivated,p as onDeactivated,I as useAlive};
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,t,o;if(Reflect.has(i,e)){var r=null===(n=i[e])||void 0===n?void 0:n.subIds;null==r||r.forEach((n=>n!==e&&u(n))),null===(o=null===(t=i[e])||void 0===t?void 0:t.dispose)||void 0===o||o.call(t),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,4 +1,4 @@
1
- import { ProveiderProps } from './default';
1
+ import { ProveiderProps } from "./default";
2
2
  /**
3
3
  * @description Alive
4
4
  * @param children jsx.element
@@ -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
  */
@@ -1,3 +1,3 @@
1
- import { ContextProps } from "./default";
1
+ import { ContextProps } from './default';
2
2
  declare var Context: import("solid-js").Context<ContextProps>;
3
3
  export default Context;
@@ -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
- setCurrentComponentId: (id: string | symbol) => void
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 = string
57
+ export type IAliveElementIds = string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-alive",
3
- "version": "0.2.2",
3
+ "version": "0.2.6",
4
4
  "author": "1iuxs",
5
5
  "description": "solid-alive",
6
6
  "type": "module",