solid-alive 0.2.1 → 0.2.2

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 i,createRoot as a,createComputed as l,createEffect as v,onCleanup as d}from"solid-js";var s=r({elements:{},info:{frozen:!1},setInfo:()=>{},insertElement:()=>{},onDeactivated:()=>{},onActivated:()=>{},removeAliveElements:()=>{},setCurrentComponentId:()=>{},insertCacheCb:()=>{}});function c(r){let[i,a]=t(),[l,v]=t({frozen:!0}),d="",c=new Map,f=new Map,u={onActivated:{},onDeactivated:{}};var m=e=>{var t;if(Reflect.has(i,e)){var n=null===(t=i[e])||void 0===t?void 0:t.subIds;null==n||n.forEach((t=>t!==e&&m(t))),a((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(a){var n=a.stack.split("\n"),r=n[0].includes("@")?5:6,o=n[r].trim(),i=o.includes("@")?o.split("@"):o.split(" ").slice(1);e=i[0],t=i[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(s.Provider,{value:{info:l,elements:i,setInfo:v,onActivated:e=>{h("onActivated",e)},onDeactivated:e=>{h("onDeactivated",e)},insertElement:e=>{let t=e.id;a([t],Object.assign(Object.assign({},i[t]),e))},removeAliveElements:e=>{if(e&&Array.isArray(e))for(const t of e)m(t);else for(const e of Object.values(i))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(i,e)&&a(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,r){return function(o){var{info:c,elements:u,setInfo:m,insertElement:A,setCurrentComponentId:h,insertCacheCb:p}=i(s);Reflect.has(u,t)||(m("frozen",!1),h(t),a((i=>{A({id:t,dispose:i,owner:null,component:r?e:null,element:e(o),subIds:Array.isArray(n)?new Set(n):null})})));var E=e=>{var t;if(u[e].isTop)return e;var n=null===(t=Object.values(u).find((t=>{var n;return null===(n=t.subIds)||void 0===n?void 0:n.has(e)})))||void 0===t?void 0:t.id;return n&&(n=E(n)),n||e};return f.has(E(t))||f.clear(),l((()=>{var e;if(!u[t].loaded){let n=null===(e=u[t])||void 0===e?void 0:e.element;for(;"function"==typeof n;)n=n();n instanceof HTMLElement&&p(t)}})),v((()=>{var e;m("frozen",!1),f.has(t)||u[t].loaded&&(f.add(t),m("frozen",!0),null===(e=u[t].onActivated)||void 0===e||e.forEach((e=>e())),m("frozen",!1))})),d((()=>{var e;c.frozen||(m("frozen",!0),null===(e=u[t].onDeactivated)||void 0===e||e.forEach((e=>e())))})),u[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}=i(s);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 E(){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,E as useAlive};
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};
@@ -5,4 +5,4 @@ import { JSX } from 'solid-js';
5
5
  * @param { string } id string,自己的id 值,一定要唯一
6
6
  * @param { Array<string> } [subIds] [string,...], 子组件的 id值 可不传,这样默认销毁时不会去干掉子组件,
7
7
  */
8
- export default function aliveTransfer(Component: <T>(props: T) => JSX.Element, id: string, subIds?: Array<string>, saveComponent?: boolean): <T>(props: T) => JSX.Element;
8
+ export default function aliveTransfer(Component: <T>(props: T) => JSX.Element, id: string, subIds?: Array<string>): <T>(props: T) => JSX.Element;
@@ -8,13 +8,14 @@ export interface NodeInfo {
8
8
  id: string
9
9
  loaded?: boolean
10
10
  owner: any,
11
+ props?:any
11
12
  component?: ((props:any) => JSX.Element) | null
12
13
  element?: JSX.Element | null
13
14
  subIds?: Set<string> | null
14
15
  dispose?: (() => void) | null
15
16
  onActivated?: null | Set<() => void>
16
17
  onDeactivated?: null | Set<() => void>
17
- isTop?: boolean | null
18
+ fatherId?: string
18
19
  }
19
20
 
20
21
  export interface SetElement {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-alive",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "author": "1iuxs",
5
5
  "description": "solid-alive",
6
6
  "type": "module",
@@ -10,10 +10,11 @@
10
10
  - removeAliveElements: 函数, 可传一个参数, 不传就删除所有缓存 :
11
11
  removeAliveElements(['/home'])
12
12
  - aliveForzen: 暂时不响应 路由数据变化, aliveForzen()
13
+
13
14
  - 子父 缓存/删除 问题
14
- - 如果某组件下有子组件,在父的 AliveTransfer中,
15
+ - 如果某组件下有子组件,在父的 aliveTransfer中,
15
16
  第三个参数,为对象 写上子组件的唯一id: {children:['/childrenId','asf',...]}
16
- - 使用见下图, 也可用 -removeAliveElements 删除
17
+ - 使用见下图, 也可用 removeAliveElements 删除
17
18
 
18
19
 
19
20
 
@@ -22,7 +23,7 @@
22
23
  ```jsx
23
24
  import { render } from 'solid-js/web'
24
25
  import App from './App'
25
- import { aliveProvider } from 'solid-alive'
26
+ import { AliveProvider } from 'solid-alive'
26
27
 
27
28
  const root = document.getElementById('root')
28
29
 
@@ -33,7 +34,7 @@ render(() =>
33
34
  , root!)
34
35
  ```
35
36
 
36
- 2 /App.tsx ,在 solid-alive 中 有 AliveTransfer, 参数: JSX , id:string, children?:[string..]
37
+ 2 /App.tsx ,在 solid-alive 中 有 aliveTransfer, 参数: JSX , id:string, children?:[string..]
37
38
  ```jsx
38
39
  import { Route, Router } from '@solidjs/router';
39
40
  import { aliveTransfer } from 'solid-alive';
@@ -48,10 +49,9 @@ import Single from './views/Blog/Single';
48
49
 
49
50
  const HomeTransfer = aliveTransfer(Home, '/')
50
51
  const AboutTransfer = aliveTransfer(About, '/about')
51
- const ShopTransfer = aliveTransfer(Shop, '/shop',['/shopPage'])
52
+ const ShopTransfer = aliveTransfer(Shop, '/shop', ['/shopPage'])
52
53
  const ShopPageTransfer = aliveTransfer(ShopPage, '/shopPage')
53
54
  const BlogTransfer = aliveTransfer(Blog, '/blog', ['contact', 'single'])
54
- const SingleTsf = aliveTransfer(Single,'single')
55
55
 
56
56
  export default function App() {
57
57
  return (
@@ -89,7 +89,6 @@ import { onActivated,onDeactivated,useAlive, AliveComponent } from "solid-alive
89
89
  export default function Single() {
90
90
  const { removeAliveElements,aliveFrozen } = useAlive()
91
91
 
92
- let divRef: Element | undefined = undefined
93
92
  const click = () => {
94
93
  removeAliveElements(['/about']) // delete '/about'; 删除 /about
95
94
  // removeAliveElements() // delete all alive element; 会删除所有缓存的组件
@@ -126,7 +125,7 @@ export default function Single() {
126
125
  /** App.tsx */
127
126
  import { createEffect, lazy, type Component } from 'solid-js'
128
127
  import { Route, Router } from '@solidjs/router'
129
- import { useAlive,AliveTransfer } from "solid-alive"
128
+ import { useAlive, aliveTransfer } from "solid-alive"
130
129
 
131
130
  const modules = import.meta.glob<{ default: Component<any> }>([
132
131
  './views/**/**.tsx',
@@ -171,7 +170,7 @@ const App: Component = () => {
171
170
  <Router>
172
171
  <Route component={Client}>
173
172
  {/* treeData 将 data变成 树结构数据 */}
174
- {transferRouter(treeData(data, 'id', 'parentId'))}
173
+ {transferRouter(treeData(data))}
175
174
  </Route>
176
175
  </Router>
177
176
  )