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 +1 -1
- package/dist/types/AliveProvider.d.ts +2 -2
- package/dist/types/aliveTransfer.d.ts +1 -1
- package/dist/types/default.d.ts +16 -20
- package/dist/types/useAlive.d.ts +3 -3
- package/package.json +1 -1
- package/readme.md +4 -3
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
|
|
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
|
|
1
|
+
import { ProveiderProps } from "./default";
|
|
2
2
|
/**
|
|
3
3
|
* @description Alive
|
|
4
4
|
* @param children jsx.element
|
|
5
|
-
* @param {Arrya<string> | null} [
|
|
5
|
+
* @param {Arrya<string> | null} [include] 哪些路由要缓存, 不写默认缓存所有
|
|
6
6
|
*/
|
|
7
7
|
export default function AliveProvider(props: ProveiderProps): import("solid-js").JSX.Element;
|
package/dist/types/default.d.ts
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
import { JSX } from 'solid-js'
|
|
1
|
+
import { JSX, Accessor } from 'solid-js'
|
|
2
2
|
|
|
3
|
-
interface
|
|
4
|
-
aliveIds?: Array<string> | null
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface ProveiderProps {
|
|
3
|
+
export interface ProveiderProps {
|
|
8
4
|
children: JSX.Element
|
|
9
|
-
|
|
5
|
+
include?: Array<string> | null
|
|
10
6
|
}
|
|
11
7
|
|
|
12
|
-
export type tActivated =
|
|
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?:
|
|
15
|
+
subIds?: Array<string> | null
|
|
21
16
|
dispose?: (() => void) | null
|
|
22
|
-
onActivated?:
|
|
23
|
-
onDeactivated?:
|
|
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
|
|
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 {
|
package/dist/types/useAlive.d.ts
CHANGED
|
@@ -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:
|
|
11
|
-
onDeactivated:
|
|
10
|
+
onActivated: (cb: () => void) => void;
|
|
11
|
+
onDeactivated: (cb: () => void) => void;
|
|
12
12
|
removeAliveElements: (ids?: Array<import("./default").IAliveElementIds>) => void;
|
|
13
|
-
aliveFrozen: () =>
|
|
13
|
+
aliveFrozen: () => boolean;
|
|
14
14
|
};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
### 描述(describe)
|
|
6
6
|
- 用于 solid 组件缓存,只测试过2级路由缓存
|
|
7
7
|
- AliveProvider
|
|
8
|
-
-
|
|
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
|
-
//
|
|
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!)
|