houdini-react 1.3.7 → 1.3.8
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/build/plugin/index.d.ts +1 -3
- package/build/plugin/state.d.ts +3 -0
- package/build/plugin-cjs/index.js +238 -240
- package/build/plugin-esm/index.js +237 -237
- package/build/runtime/routing/Router.d.ts +6 -32
- package/build/runtime/routing/hooks.d.ts +40 -0
- package/build/runtime/routing/index.d.ts +1 -0
- package/build/runtime-cjs/hooks/useDocumentHandle.js +4 -4
- package/build/runtime-cjs/hooks/useDocumentStore.js +2 -2
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +2 -2
- package/build/runtime-cjs/hooks/useMutation.js +2 -2
- package/build/runtime-cjs/routing/Router.d.ts +6 -32
- package/build/runtime-cjs/routing/Router.js +11 -62
- package/build/runtime-cjs/routing/hooks.d.ts +40 -0
- package/build/runtime-cjs/routing/hooks.js +89 -0
- package/build/runtime-cjs/routing/index.d.ts +1 -0
- package/build/runtime-cjs/routing/index.js +1 -0
- package/build/runtime-esm/hooks/useDocumentHandle.js +1 -1
- package/build/runtime-esm/hooks/useDocumentStore.js +1 -1
- package/build/runtime-esm/hooks/useDocumentSubscription.js +1 -1
- package/build/runtime-esm/hooks/useMutation.js +1 -1
- package/build/runtime-esm/routing/Router.d.ts +6 -32
- package/build/runtime-esm/routing/Router.js +3 -49
- package/build/runtime-esm/routing/hooks.d.ts +40 -0
- package/build/runtime-esm/routing/hooks.js +53 -0
- package/build/runtime-esm/routing/index.d.ts +1 -0
- package/build/runtime-esm/routing/index.js +1 -0
- package/package.json +2 -2
|
@@ -5,9 +5,10 @@ import { marshalSelection, marshalInputs } from "$houdini/runtime/lib/scalars";
|
|
|
5
5
|
import { find_match } from "$houdini/runtime/router/match";
|
|
6
6
|
import React from "react";
|
|
7
7
|
import { useContext } from "react";
|
|
8
|
+
import { suspense_cache } from "./cache";
|
|
8
9
|
import { useDocumentHandle } from "../hooks/useDocumentHandle";
|
|
9
10
|
import { useDocumentStore } from "../hooks/useDocumentStore";
|
|
10
|
-
import {
|
|
11
|
+
import { Context, useRouterContext, useSession, useLocation, LocationContext } from "./hooks";
|
|
11
12
|
const PreloadWhich = {
|
|
12
13
|
component: "component",
|
|
13
14
|
data: "data",
|
|
@@ -82,7 +83,6 @@ function Router({
|
|
|
82
83
|
}
|
|
83
84
|
) });
|
|
84
85
|
}
|
|
85
|
-
const useLocation = () => useContext(LocationContext);
|
|
86
86
|
function usePageData({
|
|
87
87
|
page,
|
|
88
88
|
variables,
|
|
@@ -322,20 +322,6 @@ function RouterContextProvider({
|
|
|
322
322
|
}
|
|
323
323
|
);
|
|
324
324
|
}
|
|
325
|
-
const Context = React.createContext(null);
|
|
326
|
-
const useRouterContext = () => {
|
|
327
|
-
const ctx = React.useContext(Context);
|
|
328
|
-
if (!ctx) {
|
|
329
|
-
throw new Error("Could not find router context");
|
|
330
|
-
}
|
|
331
|
-
return ctx;
|
|
332
|
-
};
|
|
333
|
-
function useClient() {
|
|
334
|
-
return useRouterContext().client;
|
|
335
|
-
}
|
|
336
|
-
function useCache() {
|
|
337
|
-
return useRouterContext().cache;
|
|
338
|
-
}
|
|
339
325
|
function updateLocalSession(session) {
|
|
340
326
|
window.dispatchEvent(
|
|
341
327
|
new CustomEvent("_houdini_session_", {
|
|
@@ -344,37 +330,10 @@ function updateLocalSession(session) {
|
|
|
344
330
|
})
|
|
345
331
|
);
|
|
346
332
|
}
|
|
347
|
-
function useSession() {
|
|
348
|
-
const ctx = useRouterContext();
|
|
349
|
-
const updateSession = (newSession) => {
|
|
350
|
-
ctx.data_cache.clear();
|
|
351
|
-
ctx.setSession(newSession);
|
|
352
|
-
const auth = configFile.router?.auth;
|
|
353
|
-
if (!auth) {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
const url = "redirect" in auth ? auth.redirect : auth.url;
|
|
357
|
-
fetch(url, {
|
|
358
|
-
method: "POST",
|
|
359
|
-
body: JSON.stringify(newSession),
|
|
360
|
-
headers: {
|
|
361
|
-
"Content-Type": "application/json",
|
|
362
|
-
Accept: "application/json"
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
};
|
|
366
|
-
return [ctx.session, updateSession];
|
|
367
|
-
}
|
|
368
333
|
function useCurrentVariables() {
|
|
369
334
|
return React.useContext(VariableContext);
|
|
370
335
|
}
|
|
371
336
|
const VariableContext = React.createContext(null);
|
|
372
|
-
const LocationContext = React.createContext({
|
|
373
|
-
pathname: "",
|
|
374
|
-
params: {},
|
|
375
|
-
goto: () => {
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
337
|
function useQueryResult(name) {
|
|
379
338
|
const { data_cache, artifact_cache } = useRouterContext();
|
|
380
339
|
const store_ref = data_cache.get(name);
|
|
@@ -530,12 +489,7 @@ export {
|
|
|
530
489
|
RouterContextProvider,
|
|
531
490
|
router_cache,
|
|
532
491
|
updateLocalSession,
|
|
533
|
-
useCache,
|
|
534
|
-
useClient,
|
|
535
492
|
useCurrentVariables,
|
|
536
|
-
useLocation,
|
|
537
493
|
useQueryResult,
|
|
538
|
-
useRoute
|
|
539
|
-
useRouterContext,
|
|
540
|
-
useSession
|
|
494
|
+
useRoute
|
|
541
495
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
2
|
+
import type { DocumentStore, HoudiniClient } from '$houdini/runtime/client';
|
|
3
|
+
import type { LRUCache } from '$houdini/runtime/lib/lru';
|
|
4
|
+
import type { GraphQLObject, GraphQLVariables, QueryArtifact } from '$houdini/runtime/lib/types';
|
|
5
|
+
import { default as React } from 'react';
|
|
6
|
+
import type { SuspenseCache } from './cache';
|
|
7
|
+
export type PageComponent = React.ComponentType<{
|
|
8
|
+
url: string;
|
|
9
|
+
}>;
|
|
10
|
+
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
11
|
+
resolve: () => void;
|
|
12
|
+
reject: (message: string) => void;
|
|
13
|
+
}>;
|
|
14
|
+
type RouterContext = {
|
|
15
|
+
client: HoudiniClient;
|
|
16
|
+
cache: Cache;
|
|
17
|
+
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
18
|
+
component_cache: SuspenseCache<PageComponent>;
|
|
19
|
+
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
20
|
+
ssr_signals: PendingCache;
|
|
21
|
+
last_variables: LRUCache<GraphQLVariables>;
|
|
22
|
+
session: App.Session;
|
|
23
|
+
setSession: (newSession: Partial<App.Session>) => void;
|
|
24
|
+
};
|
|
25
|
+
export declare const Context: React.Context<RouterContext | null>;
|
|
26
|
+
export declare const LocationContext: React.Context<{
|
|
27
|
+
pathname: string;
|
|
28
|
+
params: Record<string, any>;
|
|
29
|
+
goto: (url: string) => void;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const useLocation: () => {
|
|
32
|
+
pathname: string;
|
|
33
|
+
params: Record<string, any>;
|
|
34
|
+
goto: (url: string) => void;
|
|
35
|
+
};
|
|
36
|
+
export declare const useRouterContext: () => RouterContext;
|
|
37
|
+
export declare function useClient(): HoudiniClient;
|
|
38
|
+
export declare function useCache(): Cache;
|
|
39
|
+
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import configFile from "$houdini/runtime/imports/config";
|
|
2
|
+
import { useContext, default as React } from "react";
|
|
3
|
+
const Context = React.createContext(null);
|
|
4
|
+
const LocationContext = React.createContext({
|
|
5
|
+
pathname: "",
|
|
6
|
+
params: {},
|
|
7
|
+
goto: () => {
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
const useLocation = () => useContext(LocationContext);
|
|
11
|
+
const useRouterContext = () => {
|
|
12
|
+
const ctx = React.useContext(Context);
|
|
13
|
+
if (!ctx) {
|
|
14
|
+
throw new Error("Could not find router context");
|
|
15
|
+
}
|
|
16
|
+
return ctx;
|
|
17
|
+
};
|
|
18
|
+
function useClient() {
|
|
19
|
+
return useRouterContext().client;
|
|
20
|
+
}
|
|
21
|
+
function useCache() {
|
|
22
|
+
return useRouterContext().cache;
|
|
23
|
+
}
|
|
24
|
+
function useSession() {
|
|
25
|
+
const ctx = useRouterContext();
|
|
26
|
+
const updateSession = (newSession) => {
|
|
27
|
+
ctx.data_cache.clear();
|
|
28
|
+
ctx.setSession(newSession);
|
|
29
|
+
const auth = configFile.router?.auth;
|
|
30
|
+
if (!auth) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const url = "redirect" in auth ? auth.redirect : auth.url;
|
|
34
|
+
fetch(url, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
body: JSON.stringify(newSession),
|
|
37
|
+
headers: {
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
Accept: "application/json"
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
return [ctx.session, updateSession];
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
Context,
|
|
47
|
+
LocationContext,
|
|
48
|
+
useCache,
|
|
49
|
+
useClient,
|
|
50
|
+
useLocation,
|
|
51
|
+
useRouterContext,
|
|
52
|
+
useSession
|
|
53
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "houdini-react",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
4
4
|
"description": "The React plugin for houdini",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"recast": "^0.23.1",
|
|
43
43
|
"rollup": "^4.28.1",
|
|
44
44
|
"use-deep-compare-effect": "^1.8.1",
|
|
45
|
-
"houdini": "^1.5.
|
|
45
|
+
"houdini": "^1.5.4"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|
|
48
48
|
"build"
|