wildpig 2.2.2 → 2.2.4

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/index.ts CHANGED
@@ -1,20 +1,5 @@
1
1
 
2
- import { onAfterStartServer } from "./src/hooks/afterStartServer";
3
- import { defineConfig } from "./src/config";
4
- import { serverDataStore } from "./src/store/serverDataStore";
5
- import { ServerDataGuard } from "./src/router/ServerDataGuard";
6
- import type { WildPigRouteObject } from "./src/router/types";
7
-
8
- export {
9
- // config
10
- defineConfig,
11
-
12
- // hook
13
- onAfterStartServer,
14
-
15
-
16
- // router
17
- serverDataStore,
18
- ServerDataGuard,
19
- WildPigRouteObject
20
- };
2
+ export { onAfterStartServer } from "./src/hooks/afterStartServer";
3
+ export { defineConfig } from "./src/config";
4
+ export { ServerDataGuard } from "./src/router/ServerDataGuard";
5
+ export type { WildPigRouteObject } from "./src/router/types";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wildpig",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "author": "eriktse",
5
5
  "type": "module",
6
6
  "peerDependencies": {
@@ -2,7 +2,6 @@ import { createBrowserRouter } from "react-router";
2
2
  import routes from "../router";
3
3
  import { hydrateRoot } from "react-dom/client"
4
4
  // 这个文件由Vite加载
5
- // 这个文件由Vite加载
6
5
  let App: any;
7
6
  try{
8
7
  App = (await import('/src/App.tsx'!)).App;
@@ -1,6 +1,6 @@
1
1
  import { useEffect } from "react"
2
2
  import { matchRoutes, Outlet, useLocation, useNavigate } from "react-router"
3
- import { serverDataStore } from "../store/serverDataStore";
3
+ import { getServerDataStore } from "../store/serverDataStore";
4
4
  import { pageRoutes } from "./pageRoutes";
5
5
 
6
6
  export const ServerDataGuard = () => {
@@ -8,7 +8,7 @@ export const ServerDataGuard = () => {
8
8
  const navigate = useNavigate();
9
9
  useEffect(() => {
10
10
  // serverData清空
11
- serverDataStore.set(undefined);
11
+ getServerDataStore<any>().set(undefined);
12
12
 
13
13
  const pathname = location.pathname;
14
14
  const matches = matchRoutes(pageRoutes, pathname);
@@ -36,7 +36,7 @@ export const ServerDataGuard = () => {
36
36
  }
37
37
 
38
38
  fetch(serverDataApi).then(res => res.json()).then(data => {
39
- serverDataStore.set(data);
39
+ getServerDataStore<any>().set(data);
40
40
  if(data.title){
41
41
  document.title = data.title;
42
42
  }
@@ -0,0 +1,9 @@
1
+ import { atom, PreinitializedWritableAtom } from "nanostores";
2
+ import { wildpigGlobalMap } from "../utils/server/globalMap";
3
+
4
+ export const getServerDataStore = <T>(): PreinitializedWritableAtom<T | undefined> & object => {
5
+ if(!wildpigGlobalMap.getItem("__WildpigServerDataStore__")){
6
+ wildpigGlobalMap.setItem("__WildpigServerDataStore__", atom<T | undefined>(undefined));
7
+ }
8
+ return wildpigGlobalMap.getItem("__WildpigServerDataStore__") as PreinitializedWritableAtom<T | undefined> & object;
9
+ }
package/store.ts ADDED
@@ -0,0 +1,3 @@
1
+
2
+
3
+ export { getServerDataStore } from "./src/store/serverDataStore";
@@ -1,4 +0,0 @@
1
- import { atom } from "nanostores";
2
-
3
-
4
- export const serverDataStore = atom<any>(undefined);