solid-alive 0.3.0 → 0.3.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 +1 -1
- package/dist/types/AliveProvider.d.ts +1 -6
- package/dist/types/active.d.ts +2 -0
- package/dist/types/aliveTransfer.d.ts +1 -7
- package/dist/types/context.d.ts +9 -3
- package/dist/types/index.d.ts +4 -5
- package/dist/types/nextTick.d.ts +1 -0
- package/dist/types/types.d.ts +34 -0
- package/package.json +6 -6
- package/readme.md +1 -30
- package/dist/types/AliveComponent.d.ts +0 -6
- package/dist/types/default.d.ts +0 -54
- package/dist/types/useAlive.d.ts +0 -14
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createComponent as e}from"solid-js/web";import{
|
|
1
|
+
import{createComponent as e}from"solid-js/web";import{createContext as t,useContext as n,createRoot as r,getOwner as i,onCleanup as l,runWithOwner as o,createEffect as s,untrack as d}from"solid-js";import{produce as v,createStore as a}from"solid-js/store";const u=Symbol("currentId"),c=Symbol("setActiveCb");var m=t({elements:{},setElements:()=>{},setActiveCb:()=>{},aliveIds:()=>{}});const f=t({[u]:void 0,[c]:()=>{}});var A=(t,n,r)=>e(f.Provider,{value:{[u]:r,[c]:n},get children(){return t()}});function y(e,t,s){return function(d){var a,u,c=n(m);return(null===(a=c.aliveIds())||void 0===a?void 0:a.includes(t))?(c.elements[t]?null===(u=c.elements[t].onActivated)||void 0===u||u.forEach((e=>e())):(c.setElements({[t]:{id:t,subsets:Array.isArray(s)?s:null}}),r((n=>{c.setElements(v((r=>{r[t].dispose=n,r[t].id=t,r[t].owner=i(),r[t].element=A((()=>e(d)),c.setActiveCb,t)})))}))),l((()=>{var e;null===(e=c.elements[t].onDeactivated)||void 0===e||e.forEach((e=>e()))})),c.elements[t].owner&&o(c.elements[t].owner,(()=>c.elements[t].element))):A((()=>e(d)))}}function h(t){const[n,r]=a(),i=e=>{var t,l,o;if(Array.isArray(e))for(var s of e)i(null===(t=n[s])||void 0===t?void 0:t.subsets),null===(o=null===(l=n[s])||void 0===l?void 0:l.dispose)||void 0===o||o.call(l),r({[s]:void 0})};return s((e=>{var n=Array.isArray(t.include)?t.include:[];if(e.length>n.length){var r=new Set(n);i(e.filter((e=>!r.has(e))))}return n}),Array.isArray(t.include)?t.include:[]),e(m.Provider,{value:{elements:n,setElements:r,setActiveCb:(e,t,n,i)=>{r(v((r=>{r[e][t]?r[e][t][i](n):"add"===i&&(r[e][t]=new Set([n]))})))},aliveIds:()=>t.include},get children(){return t.children}})}function p(e,t){d((()=>{var r,i=n(f),o=i[u];o&&(null===(r=i[c])||void 0===r||r.call(i,o,e,t,"add"),"onActivated"===e&&s((()=>{!function(e){"undefined"!=typeof Promise&&"function"==typeof Promise.prototype.then?Promise.resolve().then(e):setTimeout(e)}(t)})),l((()=>{var n;null===(n=i[c])||void 0===n||n.call(i,o,e,t,"delete"),t=null})))}))}function b(e){p("onActivated",e)}function w(e){p("onDeactivated",e)}export{h as AliveProvider,y as aliveTransfer,b as onActivated,w as onDeactivated};
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import { ProveiderProps } from "./
|
|
2
|
-
/**
|
|
3
|
-
* @description Alive
|
|
4
|
-
* @param children jsx.element
|
|
5
|
-
* @param {Arrya<string> | null} [include] 哪些路由要缓存, 不写默认缓存所有
|
|
6
|
-
*/
|
|
1
|
+
import { ProveiderProps } from "./types";
|
|
7
2
|
export default function AliveProvider(props: ProveiderProps): import("solid-js").JSX.Element;
|
|
@@ -1,8 +1,2 @@
|
|
|
1
1
|
import { JSX } from "solid-js";
|
|
2
|
-
|
|
3
|
-
* @description Alive 组件用的 转换函数; aliveTransfer(Comp, ‘/home’)
|
|
4
|
-
* @param { ()=> JSX.Element } Component () => JSX.Element
|
|
5
|
-
* @param { string } id string,自己的id 值,一定要唯一
|
|
6
|
-
* @param { Array<string> } [subIds] [string,...], 子组件的 id值 可不传,这样默认销毁时不会去干掉子组件,
|
|
7
|
-
*/
|
|
8
|
-
export default function aliveTransfer(Component: <T>(props: T) => JSX.Element, id: string, subIds?: Array<string>): <T>(props: T) => any;
|
|
2
|
+
export default function aliveTransfer(Component: <T>(props: T) => JSX.Element, id: string, subsets?: Array<string>): <T>(props: T) => JSX.Element;
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare
|
|
3
|
-
export
|
|
1
|
+
import { Context } from "./types";
|
|
2
|
+
export declare const CURRENTID: unique symbol;
|
|
3
|
+
export declare const SETACTIVECB: unique symbol;
|
|
4
|
+
declare const _default: import("solid-js").Context<Context>;
|
|
5
|
+
export default _default;
|
|
6
|
+
export declare const ChildContext: import("solid-js").Context<{
|
|
7
|
+
[CURRENTID]: string | undefined;
|
|
8
|
+
[SETACTIVECB]?: Context["setActiveCb"];
|
|
9
|
+
}>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export { AliveComponent, AliveProvider, aliveTransfer, onActivated, onDeactivated, useAlive, };
|
|
1
|
+
import aliveTransfer from "./aliveTransfer";
|
|
2
|
+
import AliveProvider from "./AliveProvider";
|
|
3
|
+
import { onActivated, onDeactivated } from "./active";
|
|
4
|
+
export { aliveTransfer, AliveProvider, onActivated, onDeactivated };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function nextTick(cb: () => void): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Owner, JSX } from "solid-js"
|
|
2
|
+
import { SetStoreFunction } from "solid-js/store"
|
|
3
|
+
|
|
4
|
+
export type EmitType = keyof Emit
|
|
5
|
+
|
|
6
|
+
export type EmitValue<T extends EmitType> = Emit[T]
|
|
7
|
+
|
|
8
|
+
export type Activate = "onActivated" | "onDeactivated"
|
|
9
|
+
|
|
10
|
+
export interface Emit {
|
|
11
|
+
onActivated: () => void
|
|
12
|
+
onDeactivated: () => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ProveiderProps {
|
|
16
|
+
children: JSX.Element
|
|
17
|
+
include?: Array<string>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Element {
|
|
21
|
+
id: string
|
|
22
|
+
element: JSX.Element
|
|
23
|
+
dispose?: () => void
|
|
24
|
+
onActivated?: Set<() => void>
|
|
25
|
+
onDeactivated?: Set<() => void>
|
|
26
|
+
subsets?: Array<string>
|
|
27
|
+
owner?: Owner | null
|
|
28
|
+
}
|
|
29
|
+
export interface Context {
|
|
30
|
+
elements: Record<string, Element>
|
|
31
|
+
setElements: SetStoreFunction<{}>
|
|
32
|
+
aliveIds: ()=> Array<string> | undefined
|
|
33
|
+
setActiveCb: (id:string,t: Activate, cb: () => void, t1: 'add'| 'delete') => void
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-alive",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"author": "1iuxs",
|
|
5
5
|
"description": "solid-alive",
|
|
6
6
|
"type": "module",
|
|
@@ -32,21 +32,21 @@
|
|
|
32
32
|
},
|
|
33
33
|
"license": "ISC",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"solid-js": "^1.
|
|
35
|
+
"solid-js": "^1.9.3"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@rollup/plugin-json": "^6.1.0",
|
|
39
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
39
|
+
"@rollup/plugin-node-resolve": "^15.3.1",
|
|
40
40
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
41
41
|
"@types/css-modules": "^1.0.5",
|
|
42
|
-
"autoprefixer": "^10.4.
|
|
43
|
-
"rollup": "^4.
|
|
42
|
+
"autoprefixer": "^10.4.20",
|
|
43
|
+
"rollup": "^4.29.2",
|
|
44
44
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
45
45
|
"rollup-plugin-postcss": "^4.0.2",
|
|
46
46
|
"rollup-plugin-serve": "^1.1.1",
|
|
47
47
|
"rollup-plugin-terser": "^7.0.2",
|
|
48
48
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
49
49
|
"rollup-preset-solid": "^2.0.1",
|
|
50
|
-
"typescript": "^5.
|
|
50
|
+
"typescript": "^5.7.2"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/readme.md
CHANGED
|
@@ -5,19 +5,14 @@
|
|
|
5
5
|
### 描述(describe)
|
|
6
6
|
- 用于 solid 组件缓存,只测试过2级路由缓存
|
|
7
7
|
- AliveProvider
|
|
8
|
-
- include : 数组,
|
|
9
|
-
- AliveComponent 不要在 有缓存 的组件中使用
|
|
8
|
+
- include : 数组, ['/','/about'], 当数据变少时, 会自动去删除少的数据缓存
|
|
10
9
|
- 在 useAlive
|
|
11
|
-
- removeAliveElements: 函数, 可传一个参数, 不传就删除所有缓存 :
|
|
12
|
-
removeAliveElements(['/home'])
|
|
13
10
|
- onActivated
|
|
14
11
|
- onDeactivated
|
|
15
|
-
- aliveForzen: 暂时不响应 路由数据变化, aliveForzen()
|
|
16
12
|
|
|
17
13
|
- 子父 缓存/删除 问题
|
|
18
14
|
- 如果某组件下有子组件,在父的 aliveTransfer中,
|
|
19
15
|
第三个参数,为对象 写上子组件的唯一id: {children:['/childrenId','asf',...]}
|
|
20
|
-
- 使用见下图, 也可用 removeAliveElements 删除
|
|
21
16
|
|
|
22
17
|
|
|
23
18
|
|
|
@@ -30,8 +25,6 @@ import { AliveProvider } from 'solid-alive'
|
|
|
30
25
|
|
|
31
26
|
const root = document.getElementById('root')
|
|
32
27
|
|
|
33
|
-
// include, 不传 默认缓存所有: include={['/','/about']}
|
|
34
|
-
// When the data decreases, the reduced cache data will be automatically deleted
|
|
35
28
|
render(() =>
|
|
36
29
|
<AliveProvider include={[]}>
|
|
37
30
|
<App />
|
|
@@ -93,10 +86,6 @@ import { onActivated,onDeactivated,useAlive, AliveComponent } from "solid-alive
|
|
|
93
86
|
export default function Single() {
|
|
94
87
|
const { removeAliveElements,aliveFrozen } = useAlive()
|
|
95
88
|
|
|
96
|
-
const click = () => {
|
|
97
|
-
removeAliveElements(['/about']) // delete '/about'; 删除 /about
|
|
98
|
-
// removeAliveElements() // delete all alive element; 会删除所有缓存的组件
|
|
99
|
-
}
|
|
100
89
|
|
|
101
90
|
//todo call 这个会被调用
|
|
102
91
|
onActivated(()=>{
|
|
@@ -114,10 +103,6 @@ export default function Single() {
|
|
|
114
103
|
return (
|
|
115
104
|
<div>
|
|
116
105
|
<h2>Single</h2>
|
|
117
|
-
{ /** 这个 AliveComponent 最好是在 未缓存的组件 中使用, 不然生命周期不同步 */ }
|
|
118
|
-
<AliveComponent id={'home1'}>
|
|
119
|
-
<Home />
|
|
120
|
-
</AliveComponent>
|
|
121
106
|
<input type="text" style={{ border: '2px solid red' }} />
|
|
122
107
|
</div>
|
|
123
108
|
)
|
|
@@ -156,20 +141,6 @@ const App: Component = () => {
|
|
|
156
141
|
const { aliveFrozen } = useAlive()
|
|
157
142
|
|
|
158
143
|
const [data, setData] = createStore<MenuData[]>([])
|
|
159
|
-
const a: MenuData = {
|
|
160
|
-
id: 2,
|
|
161
|
-
text: 'ABOUT',
|
|
162
|
-
path: '/about',
|
|
163
|
-
realPath: '/About/index.tsx',
|
|
164
|
-
parentId: null,
|
|
165
|
-
}
|
|
166
|
-
const addRoute =()=>{
|
|
167
|
-
aliveFrozen() // 暂时不响应下面数据变化
|
|
168
|
-
setData(d => {
|
|
169
|
-
return [...d, a]
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
|
|
173
144
|
return (
|
|
174
145
|
<Router>
|
|
175
146
|
<Route component={Client}>
|
package/dist/types/default.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { JSX, Accessor } from 'solid-js'
|
|
2
|
-
|
|
3
|
-
export interface ProveiderProps {
|
|
4
|
-
children: JSX.Element
|
|
5
|
-
include?: Array<string> | null
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type tActivated = 'onActivated' | 'onDeactivated'
|
|
9
|
-
|
|
10
|
-
export interface NodeInfo {
|
|
11
|
-
id: string
|
|
12
|
-
owner?: any
|
|
13
|
-
component?: ((props: any) => JSX.Element) | null
|
|
14
|
-
element?: JSX.Element | null
|
|
15
|
-
subIds?: Array<string> | null
|
|
16
|
-
dispose?: (() => void) | null
|
|
17
|
-
onActivated?: Array<() => void> | null
|
|
18
|
-
onDeactivated?: Array<() => void> | null
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface SetElement {
|
|
22
|
-
(id: string, values: NodeInfo): void
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface StoreProps {
|
|
26
|
-
[key: string]: NodeInfo
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface IInfo {
|
|
30
|
-
frozen: boolean
|
|
31
|
-
cbOnOff: 'on' | 'off'
|
|
32
|
-
currComponentId: string | symbol,
|
|
33
|
-
aliveIds?:Array<string> | null,
|
|
34
|
-
first:boolean
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface ContextProps{
|
|
38
|
-
elements: StoreProps
|
|
39
|
-
info: IInfo
|
|
40
|
-
symbolClose: symbol
|
|
41
|
-
insertElement: (d: NodeInfo) => void
|
|
42
|
-
removeAliveElements: (ids?: Array<IAliveElementIds>) => void
|
|
43
|
-
setCb: (t: tActivated, cb: () => void) => void
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface IActive {
|
|
47
|
-
[key: string]: string
|
|
48
|
-
}
|
|
49
|
-
export interface IPrevCall {
|
|
50
|
-
onActivated: IActive
|
|
51
|
-
onDeactivated: IActive
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type IAliveElementIds = string
|
package/dist/types/useAlive.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare function onActivated(fn: () => void): void;
|
|
2
|
-
export declare function onDeactivated(fn: () => void): void;
|
|
3
|
-
/**
|
|
4
|
-
* @returns removeAliveElement 删除缓存组件,
|
|
5
|
-
* @returns aliveFrozen 让 alive 暂时失去响应, 一般在加新增路由数据时使用
|
|
6
|
-
* @returns onActivated 进入
|
|
7
|
-
* @returns onDeactivated 离开
|
|
8
|
-
*/
|
|
9
|
-
export declare function useAlive(): {
|
|
10
|
-
onActivated: (cb: () => void) => void;
|
|
11
|
-
onDeactivated: (cb: () => void) => void;
|
|
12
|
-
removeAliveElements: (ids?: Array<import("./default").IAliveElementIds>) => void;
|
|
13
|
-
aliveFrozen: () => boolean;
|
|
14
|
-
};
|