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 +1 -1
- package/dist/types/default.d.ts +3 -7
- 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 o}from"solid-js/store";import{createContext as r,createComputed as
|
|
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};
|
package/dist/types/default.d.ts
CHANGED
|
@@ -9,14 +9,13 @@ export type tActivated = 'onActivated' | 'onDeactivated'
|
|
|
9
9
|
|
|
10
10
|
export interface NodeInfo {
|
|
11
11
|
id: string
|
|
12
|
-
owner
|
|
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
|
|