solid-alive 0.2.9 → 0.3.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 CHANGED
@@ -1 +1 @@
1
- import{createComponent as e}from"solid-js/web";import{createStore as n,produce as o}from"solid-js/store";import{createContext as r,createComputed as t,on as i,useContext as l,createRoot as s,getOwner as d,onCleanup as v,runWithOwner as a}from"solid-js";var c=r({elements:{},symbolClose:Symbol("close"),info:{frozen:!1,cbOnOff:"off",currComponentId:""},insertElement:()=>{},removeAliveElements:()=>{},setCb:()=>{}});function f(r){let[l,s]=n(),d=Symbol("close"),v={frozen:!1,cbOnOff:"on",currComponentId:d,aliveIds:null};var a=e=>{var n,o,r;l[e]&&(null===(n=l[e].subIds)||void 0===n||n.forEach((n=>n!==e&&a(n))),null===(r=(o=l[e]).dispose)||void 0===r||r.call(o),s({[e]:void 0}))},f=e=>{if(Array.isArray(e))for(const n of e)a(n);else if(!e)for(const e of Object.keys(l))a(e)};return t((e=>{var n=Array.isArray(r.include),o=n?r.include:[];return v.aliveIds=n?r.include:null,e.length>o.length&&f(e.filter((e=>!o.includes(e)))),o}),Array.isArray(r.include)?r.include:[]),e(c.Provider,{value:{info:v,elements:l,symbolClose:d,setCb:(e,n)=>{var r=v.cbOnOff,t=v.currComponentId;"on"===r&&"string"==typeof t&&n&&(!l[t]&&s(t,{}),s(o((o=>{o[t][e]=[...o[t][e]||[],i([],n)]}))),"onActivated"===e&&Promise.resolve().then((()=>{v.cbOnOff="off",n(),v.cbOnOff="on"})))},insertElement:e=>{s([e.id],Object.assign(Object.assign({},l[e.id]),e))},removeAliveElements:f},get children(){return r.children}})}function u(e,n,o){return function(r){var t,{info:i,elements:f,symbolClose:u,insertElement:m}=l(c);return Array.isArray(i.aliveIds)&&!i.aliveIds.includes(n)?e(r):(f[n]?(i.currComponentId=u,i.frozen?!(null===(t=f[n].subIds)||void 0===t?void 0:t.length)&&(i.frozen=!1):Promise.resolve().then((()=>{var e;return null===(e=f[n].onActivated)||void 0===e?void 0:e.forEach((e=>e()))}))):(i.currComponentId=n,s((t=>{m({id:n,dispose:t,owner:d(),element:e(r),subIds:Array.isArray(o)?o:null})}))),v((()=>{var e,o;i.frozen||(i.currComponentId=u,null===(o=null===(e=f[n])||void 0===e?void 0:e.onDeactivated)||void 0===o||o.forEach((e=>e())))})),f[n].owner&&a(f[n].owner,(()=>f[n].element)))}}function m(n){var o=u((()=>n.children),n.id,n.subIds);return e(o,{})}function A(){var{setCb:e,removeAliveElements:n,info:o}=l(c);return{onActivated:n=>e("onActivated",n),onDeactivated:n=>e("onDeactivated",n),removeAliveElements:n,info:o}}function b(e){var{onActivated:n}=A();n(e)}function y(e){var{onDeactivated:n}=A();n(e)}function I(){var{removeAliveElements:e,info:n,onActivated:o,onDeactivated:r}=A();return{onActivated:o,onDeactivated:r,removeAliveElements:e,aliveFrozen:()=>n.frozen=!0}}export{m as AliveComponent,f as AliveProvider,u as aliveTransfer,b as onActivated,y as onDeactivated,I as useAlive};
1
+ import{createComponent as e}from"solid-js/web";import{createStore as n,produce as o}from"solid-js/store";import{createContext as r,createComputed as i,on as t,useContext as l,createRoot as s,getOwner as d,onCleanup as f,runWithOwner as v}from"solid-js";var a=r({elements:{},symbolClose:Symbol("close"),info:{frozen:!1,cbOnOff:"off",currComponentId:"",first:!0},insertElement:()=>{},removeAliveElements:()=>{},setCb:()=>{}});function c(r){let[l,s]=n(),d=Symbol("close"),f={frozen:!1,cbOnOff:"on",currComponentId:d,aliveIds:null,first:!0};var v=e=>{var n,o,r;l[e]&&(null===(n=l[e].subIds)||void 0===n||n.forEach((n=>n!==e&&v(n))),null===(r=(o=l[e]).dispose)||void 0===r||r.call(o),s({[e]:void 0}))},c=e=>{if(Array.isArray(e))for(const n of e)v(n);else if(!e)for(const e of Object.keys(l))v(e)};return i((e=>{var n=Array.isArray(r.include),o=n?r.include:[];return f.aliveIds=n?r.include:null,e.length>o.length&&c(e.filter((e=>!o.includes(e)))),o}),Array.isArray(r.include)?r.include:[]),e(a.Provider,{value:{info:f,elements:l,symbolClose:d,setCb:(e,n)=>{var r=f.cbOnOff,i=f.currComponentId;"on"===r&&"string"==typeof i&&n&&(!l[i]&&s({[i]:{id:i}}),s(o((o=>{o[i][e]=[...o[i][e]||[],t([],n)]}))),"onActivated"===e&&Promise.resolve().then((()=>{f.cbOnOff="off",n(),f.cbOnOff="on"})))},insertElement:e=>{s([e.id],Object.assign(Object.assign({},l[e.id]),e))},removeAliveElements:c},get children(){return r.children}})}function u(e,n,o){return function(r){var i,{info:t,elements:c,symbolClose:u,insertElement:m}=l(a);return Array.isArray(t.aliveIds)&&!t.aliveIds.includes(n)?e(r):(c[n]?t.frozen?!(null===(i=c[n].subIds)||void 0===i?void 0:i.length)&&(t.frozen=!1):Promise.resolve().then((()=>{var e;return null===(e=c[n].onActivated)||void 0===e?void 0:e.forEach((e=>e()))})):(t.currComponentId=n,s((i=>{m({id:n,dispose:i,owner:d(),element:e(r),subIds:Array.isArray(o)?o:null})}))),f((()=>{var e,o,r;t.frozen||(t.first&&(t.currComponentId=u,t.first=!1),!(null===(e=c[n].subIds)||void 0===e?void 0:e.length)&&(t.first=!0),t.cbOnOff="off",null===(r=null===(o=c[n])||void 0===o?void 0:o.onDeactivated)||void 0===r||r.forEach((e=>e())),t.cbOnOff="on")})),c[n].owner&&v(c[n].owner,(()=>c[n].element)))}}function m(n){var o=u((()=>n.children),n.id,n.subIds);return e(o,{})}function b(){var{setCb:e,removeAliveElements:n,info:o}=l(a);return{onActivated:n=>e("onActivated",n),onDeactivated:n=>e("onDeactivated",n),removeAliveElements:n,info:o}}function A(e){var{onActivated:n}=b();n(e)}function y(e){var{onDeactivated:n}=b();n(e)}function O(){var{removeAliveElements:e,info:n,onActivated:o,onDeactivated:r}=b();return{onActivated:o,onDeactivated:r,removeAliveElements:e,aliveFrozen:()=>n.frozen=!0}}export{m as AliveComponent,c as AliveProvider,u as aliveTransfer,A as onActivated,y as onDeactivated,O as useAlive};
@@ -9,14 +9,13 @@ export type tActivated = 'onActivated' | 'onDeactivated'
9
9
 
10
10
  export interface NodeInfo {
11
11
  id: string
12
- owner: any
12
+ owner?: any
13
13
  component?: ((props: any) => JSX.Element) | null
14
14
  element?: JSX.Element | null
15
15
  subIds?: Array<string> | null
16
16
  dispose?: (() => void) | null
17
17
  onActivated?: Array<() => void> | null
18
18
  onDeactivated?: Array<() => void> | null
19
- // fatherId?: string
20
19
  }
21
20
 
22
21
  export interface SetElement {
@@ -31,19 +30,16 @@ export interface IInfo {
31
30
  frozen: boolean
32
31
  cbOnOff: 'on' | 'off'
33
32
  currComponentId: string | symbol,
34
- aliveIds?:Array<string> | null
33
+ aliveIds?:Array<string> | null,
34
+ first:boolean
35
35
  }
36
36
 
37
- export type TSetInfo = <T extends keyof IInfo>(key: T, value: IInfo[T]) => void
38
-
39
37
  export interface ContextProps{
40
38
  elements: StoreProps
41
39
  info: IInfo
42
40
  symbolClose: symbol
43
- // setInfo: TSetInfo
44
41
  insertElement: (d: NodeInfo) => void
45
42
  removeAliveElements: (ids?: Array<IAliveElementIds>) => void
46
- // insertCacheCb: (id: string) => void
47
43
  setCb: (t: tActivated, cb: () => void) => void
48
44
  }
49
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-alive",
3
- "version": "0.2.9",
3
+ "version": "0.3.0",
4
4
  "author": "1iuxs",
5
5
  "description": "solid-alive",
6
6
  "type": "module",