solid-alive 0.2.9 → 0.3.1
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 +1 -1
- package/dist/types/AliveComponent.d.ts +0 -6
- package/dist/types/default.d.ts +0 -58
- 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 o,runWithOwner as l,createEffect as s,untrack as d}from"solid-js";import{produce as u,createStore as v}from"solid-js/store";const a=Symbol("currentId"),c=Symbol("setActiveCb");var m=t({elements:{},setElements:()=>{},setActiveCb:()=>{},aliveIds:()=>{}});const f=t({[a]:void 0,[c]:()=>{}});function A(t,s,d){return function(v){var A,y,h=n(m);return(null===(A=h.aliveIds())||void 0===A?void 0:A.includes(s))?(h.elements[s]?null===(y=h.elements[s].onActivated)||void 0===y||y.forEach((e=>e())):(h.setElements({[s]:{id:s,subsets:Array.isArray(d)?d:null}}),r((n=>{h.setElements(u((r=>{r[s].dispose=n,r[s].id=s,r[s].owner=i(),r[s].element=e(f.Provider,{get value(){return{[a]:s,[c]:h.setActiveCb}},get children(){return t(v)}})})))}))),o((()=>{var e;null===(e=h.elements[s].onDeactivated)||void 0===e||e.forEach((e=>e()))})),h.elements[s].owner&&l(h.elements[s].owner,(()=>h.elements[s].element))):t(v)}}function y(t){const[n,r]=v(),i=e=>{var t,o,l;if(Array.isArray(e))for(var s of e)i(null===(t=n[s])||void 0===t?void 0:t.subsets),null===(l=null===(o=n[s])||void 0===o?void 0:o.dispose)||void 0===l||l.call(o),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(u((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 h(e,t){d((()=>{var r=n(f),i=r[a];i&&(r[c](i,e,t,"add"),"onActivated"===e&&s((()=>{!function(e){"undefined"!=typeof Promise&&"function"==typeof Promise.prototype.then?Promise.resolve().then(e):setTimeout(e)}(t)})),o((()=>{r[c](i,e,t,"delete"),t=null})))}))}function p(e){h("onActivated",e)}function b(e){h("onDeactivated",e)}export{y as AliveProvider,A as aliveTransfer,p as onActivated,b 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) => any;
|
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
package/dist/types/default.d.ts
DELETED
|
@@ -1,58 +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
|
-
// fatherId?: string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface SetElement {
|
|
23
|
-
(id: string, values: NodeInfo): void
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface StoreProps {
|
|
27
|
-
[key: string]: NodeInfo
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface IInfo {
|
|
31
|
-
frozen: boolean
|
|
32
|
-
cbOnOff: 'on' | 'off'
|
|
33
|
-
currComponentId: string | symbol,
|
|
34
|
-
aliveIds?:Array<string> | null
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export type TSetInfo = <T extends keyof IInfo>(key: T, value: IInfo[T]) => void
|
|
38
|
-
|
|
39
|
-
export interface ContextProps{
|
|
40
|
-
elements: StoreProps
|
|
41
|
-
info: IInfo
|
|
42
|
-
symbolClose: symbol
|
|
43
|
-
// setInfo: TSetInfo
|
|
44
|
-
insertElement: (d: NodeInfo) => void
|
|
45
|
-
removeAliveElements: (ids?: Array<IAliveElementIds>) => void
|
|
46
|
-
// insertCacheCb: (id: string) => void
|
|
47
|
-
setCb: (t: tActivated, cb: () => void) => void
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface IActive {
|
|
51
|
-
[key: string]: string
|
|
52
|
-
}
|
|
53
|
-
export interface IPrevCall {
|
|
54
|
-
onActivated: IActive
|
|
55
|
-
onDeactivated: IActive
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
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
|
-
};
|