@iuxs/solid-keep-alive 0.0.2 → 0.0.3
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/README.md +2 -1
- package/dist/index.js +1 -1
- package/dist/types/aliveActive.d.ts +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -202,9 +202,10 @@ export default function C() {
|
|
|
202
202
|
```tsx
|
|
203
203
|
// @/layout/Container/index.tsx
|
|
204
204
|
import { aliveTransfer } from "@iuxs/solid-keep-alive"
|
|
205
|
-
import type { RouteSectionProps } from "@solidjs/router"
|
|
206
205
|
import Aside from "xxxx"
|
|
207
206
|
|
|
207
|
+
import type { RouteSectionProps } from "@solidjs/router"
|
|
208
|
+
|
|
208
209
|
const Aside1 = aliveTransfer(Aside, "aside", { isolated: true })
|
|
209
210
|
|
|
210
211
|
/** 最外的容器 */
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createComponent as e}from"solid-js/web";import{createStore as n,produce as t}from"solid-js/store";import{createContext as o,createMemo as s,runWithOwner as c,useContext as d,createComponent as r,createRoot as i,getOwner as l,createEffect as a,onCleanup as u}from"solid-js";const h=o(),v=o();function f(o){const[d,r]=n({}),i=s(e=>{if(!Array.isArray(o.include))return new Set([]);if(e&&e.size){for(const n of o.include)e.delete(n);e.size&&(n=e,r(t(e=>{(n=>{var t,o,s,c;for(const d of n)e[d]&&(e[d].parentId&&(null===(o=null===(t=e[e[d].parentId])||void 0===t?void 0:t.childIds)||void 0===o||o.delete(d)),e[d].hasEl=!1,e[d].init&&!e[d].noCache||(null===(c=(s=e[d]).dispose)||void 0===c||c.call(s),delete e[d]))})(n)})))}var n;return new Set(o.include)});return e(h.Provider,{value:{caches:d,include:i,currentIds:new Set,setCaches:r,setActive:(e,n,o,s)=>{"aOnceSet"===n&&"add"===s&&d[e].init&&d[e].hasEl?c(d[e].owner,o):r(t(t=>{t[e][n]?t[e][n][s](o):"add"===s&&(t[e][n]=new Set([o]))}))}},get children(){return o.children}})}let I=!1;const p=(n,o,s)=>((null==s?void 0:s.isolated)||(I=!0),function(f){var p;const S=d(h);if(!S||!o&&console.error(`[solid-
|
|
1
|
+
import{createComponent as e}from"solid-js/web";import{createStore as n,produce as t}from"solid-js/store";import{createContext as o,createMemo as s,runWithOwner as c,useContext as d,createComponent as r,createRoot as i,getOwner as l,createEffect as a,onCleanup as u}from"solid-js";const h=o(),v=o();function f(o){const[d,r]=n({}),i=s(e=>{if(!Array.isArray(o.include))return new Set([]);if(e&&e.size){for(const n of o.include)e.delete(n);e.size&&(n=e,r(t(e=>{(n=>{var t,o,s,c;for(const d of n)e[d]&&(e[d].parentId&&(null===(o=null===(t=e[e[d].parentId])||void 0===t?void 0:t.childIds)||void 0===o||o.delete(d)),e[d].hasEl=!1,e[d].init&&!e[d].noCache||(null===(c=(s=e[d]).dispose)||void 0===c||c.call(s),delete e[d]))})(n)})))}var n;return new Set(o.include)});return e(h.Provider,{value:{caches:d,include:i,currentIds:new Set,setCaches:r,setActive:(e,n,o,s)=>{"aOnceSet"===n&&"add"===s&&d[e].init&&d[e].hasEl?c(d[e].owner,o):r(t(t=>{t[e][n]?t[e][n][s](o):"add"===s&&(t[e][n]=new Set([o]))}))}},get children(){return o.children}})}let I=!1;const p=(n,o,s)=>((null==s?void 0:s.isolated)||(I=!0),function(f){var p;const S=d(h);if(!S||!o&&console.error(`[solid-keep-alive]:id='${o}' error`))return r(n,f);const C=null===(p=d(v))||void 0===p?void 0:p.id,m=()=>{var e;return!C||(null===(e=S.caches[o])||void 0===e?void 0:e.parentId)===C},w=null==s?void 0:s.isolated;if(S.caches[o])w||S.currentIds.add(o);else{const s=w?null:[...S.currentIds].at(-1);s&&S.caches[s]&&S.setCaches(t(e=>{const n=e[s];n.childIds?n.childIds.add(o):n.childIds=new Set([o])})),w||S.currentIds.add(o);const c=!S.include().has(o);S.setCaches({[o]:Object.assign({id:o,parentId:s},c&&{noCache:c})}),i(s=>S.setCaches(t(t=>{t[o].dispose=s,t[o].owner=l(),t[o].component=e(v.Provider,{get value(){return Object.assign({id:o},c&&{noCache:c})},get children(){return r(n,f)}})})))}return a(()=>{var e;const n=S.caches[o];if(n&&m()&&(!I||w||(null===(e=n.childIds)||void 0===e?void 0:e.size)||(I=!1),!n.init&&(n.hasEl||(()=>{var e,n;if(null===(n=null===(e=S.caches[o])||void 0===e?void 0:e.component)||void 0===n?void 0:n.call(e))return S.setCaches(t(e=>{e[o].hasEl=!0,e[o].owner=l();for(const n of e[o].aOnceSet||[])n();delete e[o].aOnceSet})),!0})()))){S.setCaches(o,"init",!0);for(const e of n.aSet||[])e()}}),u(()=>{const e=S.caches[o];if(!w&&(I||!e))return;if(e.parentId){if(S.currentIds.has(o)){const e=n=>{var t;for(const o of n){S.currentIds.delete(o);const n=null===(t=S.caches[o])||void 0===t?void 0:t.childIds;(null==n?void 0:n.size)&&e(n)}};e([o])}}else w||S.currentIds.clear();if(!m())return;const n=!e.noCache&&e.hasEl;n&&S.setCaches(o,"init",!1);for(const n of e.dSet||[])n();n||S.setCaches(t(e=>{var n,t,s,c;e[o].parentId&&(null===(t=null===(n=e[e[o].parentId])||void 0===n?void 0:n.childIds)||void 0===t||t.delete(o)),null===(c=(s=e[o]).dispose)||void 0===c||c.call(s),delete e[o]}))}),m()&&c(S.caches[o].owner,()=>S.caches[o].component)}),S=(e,n)=>{if("function"!=typeof n)return;const{id:t,noCache:o}=d(v)||{};if(o&&"aOnceSet"!==e)return;const s=d(h);t&&s&&(s.setActive(t,e,n,"add"),"aOnceSet"!==e&&u(()=>{s.setActive(t,e,n,"delete")}))},C=e=>{S("aSet",e)},m=e=>{S("dSet",e)},w=e=>{const[t,o]=n();return S("aOnceSet",()=>{c(l(),()=>{o(d(e))})}),t};export{f as AliveProvider,p as aliveTransfer,C as onActivated,m as onDeactivated,w as useAliveContext};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description 进入缓存
|
|
3
3
|
* ```tsx
|
|
4
|
-
* import { onActivated } from 'solid-
|
|
4
|
+
* import { onActivated } from '@iuxs/solid-keep-alive'
|
|
5
5
|
* //use
|
|
6
6
|
* onActivated(()=> console.log(234))
|
|
7
7
|
* ```
|
|
@@ -10,7 +10,7 @@ export declare const onActivated: (cb: () => void) => void;
|
|
|
10
10
|
/**
|
|
11
11
|
* @description 离开缓存
|
|
12
12
|
* ```tsx
|
|
13
|
-
* import { onDeactivated } from 'solid-
|
|
13
|
+
* import { onDeactivated } from '@iuxs/solid-keep-alive'
|
|
14
14
|
* onDeactivated(()=> console.log(234))
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
@@ -18,7 +18,7 @@ export declare const onDeactivated: (cb: () => void) => void;
|
|
|
18
18
|
/**
|
|
19
19
|
* @description 进入缓存,只会执行一次
|
|
20
20
|
* ```tsx
|
|
21
|
-
* import { onActivatedOnce } from 'solid-
|
|
21
|
+
* import { onActivatedOnce } from '@iuxs/solid-keep-alive'
|
|
22
22
|
* onDeactivated(()=> console.log(234))
|
|
23
23
|
* ```
|
|
24
24
|
*/
|