solid-alive 0.2.6 → 0.2.7
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 -1
- package/dist/types/aliveTransfer.d.ts +1 -1
- package/dist/types/default.d.ts +10 -5
- package/dist/types/useAlive.d.ts +4 -0
- package/package.json +1 -1
- package/readme.md +9 -6
- package/dist/types/utils.d.ts +0 -4
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createComponent as e}from"solid-js/web";import{createStore as n,produce as
|
|
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,6 +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} [includes] 哪些路由要缓存, 不写默认缓存所有
|
|
5
6
|
*/
|
|
6
7
|
export default function AliveProvider(props: ProveiderProps): import("solid-js").JSX.Element;
|
|
@@ -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>): <T>(props: T) =>
|
|
8
|
+
export default function aliveTransfer(Component: <T>(props: T) => JSX.Element, id: string, subIds?: Array<string>): <T>(props: T) => any;
|
package/dist/types/default.d.ts
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { JSX } from 'solid-js'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface pub{
|
|
4
|
+
aliveIds?: Array<string> | null
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface ProveiderProps {
|
|
4
8
|
children: JSX.Element
|
|
9
|
+
includes?:pub['aliveIds']
|
|
5
10
|
}
|
|
6
11
|
|
|
12
|
+
export type tActivated = "onActivated" | "onDeactivated"
|
|
13
|
+
|
|
7
14
|
export interface NodeInfo {
|
|
8
15
|
id: string
|
|
9
16
|
loaded?: boolean
|
|
10
17
|
owner: any
|
|
11
|
-
props?: any
|
|
12
18
|
component?: ((props: any) => JSX.Element) | null
|
|
13
19
|
element?: JSX.Element | null
|
|
14
20
|
subIds?: Set<string> | null
|
|
@@ -34,16 +40,15 @@ export interface IInfo {
|
|
|
34
40
|
|
|
35
41
|
export type TSetInfo = <T extends keyof IInfo>(key: T, value: IInfo[T]) => void
|
|
36
42
|
|
|
37
|
-
export interface ContextProps {
|
|
43
|
+
export interface ContextProps extends pub {
|
|
38
44
|
elements: StoreProps
|
|
39
45
|
info: IInfo
|
|
40
46
|
symbolClose: symbol
|
|
41
47
|
setInfo: TSetInfo
|
|
42
48
|
insertElement: (d: NodeInfo) => void
|
|
43
|
-
onActivated: (cb: () => void) => void
|
|
44
|
-
onDeactivated: (cb: () => void) => void
|
|
45
49
|
removeAliveElements: (ids?: Array<IAliveElementIds>) => void
|
|
46
50
|
insertCacheCb: (id: string) => void
|
|
51
|
+
setCb:(t: tActivated, cb: () => void)=>void
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
interface IActive {
|
package/dist/types/useAlive.d.ts
CHANGED
|
@@ -3,8 +3,12 @@ export declare function onDeactivated(fn: () => void): void;
|
|
|
3
3
|
/**
|
|
4
4
|
* @returns removeAliveElement 删除缓存组件,
|
|
5
5
|
* @returns aliveFrozen 让 alive 暂时失去响应, 一般在加新增路由数据时使用
|
|
6
|
+
* @returns onActivated 进入
|
|
7
|
+
* @returns onDeactivated 离开
|
|
6
8
|
*/
|
|
7
9
|
export declare function useAlive(): {
|
|
10
|
+
onActivated: typeof onActivated;
|
|
11
|
+
onDeactivated: typeof onDeactivated;
|
|
8
12
|
removeAliveElements: (ids?: Array<import("./default").IAliveElementIds>) => void;
|
|
9
13
|
aliveFrozen: () => void;
|
|
10
14
|
};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
### 描述(describe)
|
|
6
6
|
- 用于 solid 组件缓存,只测试过2级路由缓存
|
|
7
7
|
- AliveProvider
|
|
8
|
+
- includes : 数组, 不传默认缓存所有, ['/','/about']
|
|
8
9
|
- AliveComponent 不要在 有缓存 的组件中使用
|
|
9
10
|
- 在 useAlive
|
|
10
11
|
- removeAliveElements: 函数, 可传一个参数, 不传就删除所有缓存 :
|
|
11
12
|
removeAliveElements(['/home'])
|
|
13
|
+
- onActivated
|
|
14
|
+
- onDeactivated
|
|
12
15
|
- aliveForzen: 暂时不响应 路由数据变化, aliveForzen()
|
|
13
16
|
|
|
14
17
|
- 子父 缓存/删除 问题
|
|
@@ -27,6 +30,7 @@ import { AliveProvider } from 'solid-alive'
|
|
|
27
30
|
|
|
28
31
|
const root = document.getElementById('root')
|
|
29
32
|
|
|
33
|
+
// includes, 默认缓存所有
|
|
30
34
|
render(() =>
|
|
31
35
|
<AliveProvider>
|
|
32
36
|
<App />
|
|
@@ -47,11 +51,10 @@ import Blog from './views/Blog';
|
|
|
47
51
|
import Single from './views/Blog/Single';
|
|
48
52
|
|
|
49
53
|
|
|
50
|
-
const HomeTransfer = aliveTransfer(Home, '/')
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const BlogTransfer = aliveTransfer(Blog, '/blog', ['contact', 'single'])
|
|
54
|
+
const HomeTransfer = aliveTransfer(Home, '/'),
|
|
55
|
+
AboutTsf = aliveTransfer(About, '/about'),
|
|
56
|
+
BlogTsf = aliveTransfer(Blog, '/blog', ['/contact', 'single']),
|
|
57
|
+
SingleTsf = aliveTransfer(Single,'single')
|
|
55
58
|
|
|
56
59
|
export default function App() {
|
|
57
60
|
return (
|
|
@@ -99,7 +102,7 @@ export default function Single() {
|
|
|
99
102
|
console.log('Single-activeated-1')
|
|
100
103
|
})
|
|
101
104
|
|
|
102
|
-
//todo
|
|
105
|
+
//todo call 也会被调用
|
|
103
106
|
onActivated(()=>{
|
|
104
107
|
console.log('Single-activeated-2')
|
|
105
108
|
})
|
package/dist/types/utils.d.ts
DELETED