solid-alive 0.2.7 → 0.2.9

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 t,createComputed as r,on as i,useContext as l,createRoot as s,getOwner as d,createEffect as a,onCleanup as f,runWithOwner as v}from"solid-js";var c=t({elements:{},symbolClose:Symbol("close"),info:{frozen:!1,cbOnOff:"off",currComponentId:""},setInfo:()=>{},insertElement:()=>{},removeAliveElements:()=>{},insertCacheCb:()=>{},setCb:()=>{}});function u(t){let[l,s]=n(),d={frozen:!1,cbOnOff:"off",currComponentId:""},a=Symbol("close"),f=new Map,v=new Map;var u=e=>{let n=e.id,o=Object.values(l).find((e=>{var o;return null===(o=e.subIds)||void 0===o?void 0:o.has(n)}));s([n],Object.assign(Object.assign(Object.assign({},l[n]),e),{fatherId:null==o?void 0:o.id}))},m=e=>{let n=f.get(e),t=v.get(e);f.delete(e),v.delete(e),Reflect.has(l,e)&&s(o((o=>{o[e].onActivated=n,o[e].onDeactivated=t,o[e].loaded=!0})))},b=e=>{var n,o,t;if(Reflect.has(l,e)){var r=null===(n=l[e])||void 0===n?void 0:n.subIds;null==r||r.forEach((n=>n!==e&&b(n))),null===(t=(o=l[e]).dispose)||void 0===t||t.call(o),s({[e]:void 0})}},O=e=>{if(Array.isArray(e))for(const n of e)b(n);else if(!e)for(const e of Object.values(l))b(e.id)},I=(e,n)=>{var{cbOnOff:o,currComponentId:t}=d;if("on"===o&&t!==a&&n){var r={onActivated:f,onDeactivated:v}[e],l=r.get(t)||new Set;l.add(i([],n))&&r.set(t,l)}},h=(e,n)=>{d[e]=n};return r(((e=[])=>{var n=t.includes||[];if(e.length>n.length){var o=new Set(n);O(e.filter((e=>!o.has(e))))}return n}),t.includes||[]),e(c.Provider,{get value(){return{info:d,elements:l,symbolClose:a,setInfo:h,setCb:I,insertElement:u,removeAliveElements:O,insertCacheCb:m,aliveIds:t.includes}},get children(){return t.children}})}function m(e,n,o){return function(t){var{info:i,elements:u,symbolClose:m,setInfo:b,insertElement:O,insertCacheCb:I,aliveIds:h}=l(c);if(!h||!h.includes(n))return e(t);!Reflect.has(u,n)&&s((r=>{b("currComponentId",n),b("cbOnOff","on"),O({id:n,dispose:r,owner:d(),element:e(t),subIds:Array.isArray(o)?new Set(o):null})}));return r((()=>{var e;!u[n].loaded&&(e=>{for(var n,o=null===(n=u[e])||void 0===n?void 0:n.element;"function"==typeof o;)o=o();return o})(n)&&(I(n),!(null===(e=u[n].subIds)||void 0===e?void 0:e.size)&&b("currComponentId",m))})),a((()=>{var e,o,t;i.frozen?!(null===(e=u[n].subIds)||void 0===e?void 0:e.size)&&b("frozen",!1):(null===(o=u[n])||void 0===o?void 0:o.loaded)&&(b("cbOnOff","off"),null===(t=u[n].onActivated)||void 0===t||t.forEach((e=>e())),b("cbOnOff","on"))})),f((()=>{var e,o;i.frozen||(b("cbOnOff","off"),null===(o=null===(e=u[n])||void 0===e?void 0:e.onDeactivated)||void 0===o||o.forEach((e=>e())),b("cbOnOff","on"))})),u[n].owner&&v(u[n].owner,(()=>u[n].element))}}function b(n){var o=m((()=>n.children),n.id,n.subIds);return e(o,{})}function O(){var{setCb:e,removeAliveElements:n,setInfo:o}=l(c);return{onActivated:n=>e("onActivated",n),onDeactivated:n=>e("onDeactivated",n),removeAliveElements:n,setInfo:o}}function I(e){var{onActivated:n}=O();n(e)}function h(e){var{onDeactivated:n}=O();n(e)}function A(){var{removeAliveElements:e,setInfo:n}=O();return{onActivated:I,onDeactivated:h,removeAliveElements:e,aliveFrozen:()=>n("frozen",!0)}}export{b as AliveComponent,u as AliveProvider,m as aliveTransfer,I as onActivated,h as onDeactivated,A 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 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,7 +1,7 @@
1
- import { ProveiderProps } from './default';
1
+ import { ProveiderProps } from "./default";
2
2
  /**
3
3
  * @description Alive
4
4
  * @param children jsx.element
5
- * @param {Arrya<string> | null} [includes] 哪些路由要缓存, 不写默认缓存所有
5
+ * @param {Arrya<string> | null} [include] 哪些路由要缓存, 不写默认缓存所有
6
6
  */
7
7
  export default function AliveProvider(props: ProveiderProps): import("solid-js").JSX.Element;
@@ -1,4 +1,4 @@
1
- import { JSX } from 'solid-js';
1
+ import { JSX } from "solid-js";
2
2
  /**
3
3
  * @description Alive 组件用的 转换函数; aliveTransfer(Comp, ‘/home’)
4
4
  * @param { ()=> JSX.Element } Component () => JSX.Element
@@ -1,27 +1,22 @@
1
- import { JSX } from 'solid-js'
1
+ import { JSX, Accessor } from 'solid-js'
2
2
 
3
- interface pub{
4
- aliveIds?: Array<string> | null
5
- }
6
-
7
- export interface ProveiderProps {
3
+ export interface ProveiderProps {
8
4
  children: JSX.Element
9
- includes?:pub['aliveIds']
5
+ include?: Array<string> | null
10
6
  }
11
7
 
12
- export type tActivated = "onActivated" | "onDeactivated"
8
+ export type tActivated = 'onActivated' | 'onDeactivated'
13
9
 
14
10
  export interface NodeInfo {
15
11
  id: string
16
- loaded?: boolean
17
12
  owner: any
18
13
  component?: ((props: any) => JSX.Element) | null
19
14
  element?: JSX.Element | null
20
- subIds?: Set<string> | null
15
+ subIds?: Array<string> | null
21
16
  dispose?: (() => void) | null
22
- onActivated?: null | Set<() => void>
23
- onDeactivated?: null | Set<() => void>
24
- fatherId?: string
17
+ onActivated?: Array<() => void> | null
18
+ onDeactivated?: Array<() => void> | null
19
+ // fatherId?: string
25
20
  }
26
21
 
27
22
  export interface SetElement {
@@ -33,22 +28,23 @@ export interface StoreProps {
33
28
  }
34
29
 
35
30
  export interface IInfo {
36
- frozen: boolean
37
- cbOnOff: 'on' | 'off'
38
- currComponentId: string | symbol
31
+ frozen: boolean
32
+ cbOnOff: 'on' | 'off'
33
+ currComponentId: string | symbol,
34
+ aliveIds?:Array<string> | null
39
35
  }
40
36
 
41
37
  export type TSetInfo = <T extends keyof IInfo>(key: T, value: IInfo[T]) => void
42
38
 
43
- export interface ContextProps extends pub {
39
+ export interface ContextProps{
44
40
  elements: StoreProps
45
41
  info: IInfo
46
42
  symbolClose: symbol
47
- setInfo: TSetInfo
43
+ // setInfo: TSetInfo
48
44
  insertElement: (d: NodeInfo) => void
49
45
  removeAliveElements: (ids?: Array<IAliveElementIds>) => void
50
- insertCacheCb: (id: string) => void
51
- setCb:(t: tActivated, cb: () => void)=>void
46
+ // insertCacheCb: (id: string) => void
47
+ setCb: (t: tActivated, cb: () => void) => void
52
48
  }
53
49
 
54
50
  interface IActive {
@@ -7,8 +7,8 @@ export declare function onDeactivated(fn: () => void): void;
7
7
  * @returns onDeactivated 离开
8
8
  */
9
9
  export declare function useAlive(): {
10
- onActivated: typeof onActivated;
11
- onDeactivated: typeof onDeactivated;
10
+ onActivated: (cb: () => void) => void;
11
+ onDeactivated: (cb: () => void) => void;
12
12
  removeAliveElements: (ids?: Array<import("./default").IAliveElementIds>) => void;
13
- aliveFrozen: () => void;
13
+ aliveFrozen: () => boolean;
14
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-alive",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "author": "1iuxs",
5
5
  "description": "solid-alive",
6
6
  "type": "module",
package/readme.md CHANGED
@@ -5,7 +5,7 @@
5
5
  ### 描述(describe)
6
6
  - 用于 solid 组件缓存,只测试过2级路由缓存
7
7
  - AliveProvider
8
- - includes : 数组, 不传默认缓存所有, ['/','/about']
8
+ - include : 数组, 不传默认缓存所有, ['/','/about'], 当数据变少时, 会自动去删除少的数据缓存
9
9
  - AliveComponent 不要在 有缓存 的组件中使用
10
10
  - 在 useAlive
11
11
  - removeAliveElements: 函数, 可传一个参数, 不传就删除所有缓存 :
@@ -30,9 +30,10 @@ import { AliveProvider } from 'solid-alive'
30
30
 
31
31
  const root = document.getElementById('root')
32
32
 
33
- // includes, 默认缓存所有
33
+ // include, 不传 默认缓存所有: include={['/','/about']}
34
+ // When the data decreases, the reduced cache data will be automatically deleted
34
35
  render(() =>
35
- <AliveProvider>
36
+ <AliveProvider include={[]}>
36
37
  <App />
37
38
  </AliveProvider>
38
39
  , root!)