houdini-react 2.0.0-go.4 → 2.0.0-go.6

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.
@@ -0,0 +1,52 @@
1
+ // a suspense cache is an object that maintains a key-value store of
2
+ // objects. If a value is missing when get() is called, a promise
3
+ // is thrown that resolves when a value is passed to set()
4
+ import { LRUCache } from 'houdini/runtime'
5
+
6
+ export function suspense_cache<T>(initialData?: Record<string, T>): SuspenseCache<T> {
7
+ const cache = new SuspenseCache<T>()
8
+
9
+ for (const [key, value] of Object.entries(initialData ?? {})) {
10
+ cache.set(key, value)
11
+ }
12
+
13
+ return cache
14
+ }
15
+
16
+ export class SuspenseCache<_Data> extends LRUCache<_Data> {
17
+ // if get is called before set, we need to invoke a callback.
18
+ // that means we need a place to put our callbacks
19
+ #callbacks: Map<string, { resolve: () => void; reject: () => void }[]> = new Map()
20
+
21
+ get(key: string): _Data {
22
+ // if there is a value, use that
23
+ if (super.has(key)) {
24
+ return super.get(key)!
25
+ }
26
+
27
+ // we don't have a value, so we need to throw a promise
28
+ // that resolves when a value is passed to set()
29
+ throw new Promise<void>((resolve, reject) => {
30
+ this.#subscribe(key, resolve, reject)
31
+ })
32
+ }
33
+
34
+ // TODO: reject?
35
+
36
+ set(key: string, value: _Data) {
37
+ // perform the set like normal
38
+ super.set(key, value)
39
+
40
+ // if there are subscribers, resolve them
41
+ if (this.#callbacks.has(key)) {
42
+ // resolve all of the callbacks
43
+ this.#callbacks.get(key)?.forEach(({ resolve }) => resolve())
44
+ // delete the key
45
+ this.#callbacks.delete(key)
46
+ }
47
+ }
48
+
49
+ #subscribe(key: string, resolve: () => void, reject: () => void) {
50
+ this.#callbacks.set(key, [...(this.#callbacks.get(key) || []), { resolve, reject }])
51
+ }
52
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Router'
2
+ export { type SuspenseCache, suspense_cache } from './cache'
@@ -0,0 +1 @@
1
+ export { renderToStream } from 'react-streaming-compat/server';
@@ -0,0 +1,4 @@
1
+ import { renderToStream } from "react-streaming-compat/server";
2
+ export {
3
+ renderToStream
4
+ };
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,3 @@
1
+ import { VitePluginContext } from 'houdini/vite';
2
+ import { PluginOption } from 'vite';
3
+ export default function (ctx: VitePluginContext): PluginOption;
package/vite/index.js ADDED
@@ -0,0 +1,11 @@
1
+ function vite_default(ctx) {
2
+ return {
3
+ name: "houdini-react",
4
+ configureServer(server) {
5
+ console.log("greetings from react vite plugin");
6
+ }
7
+ };
8
+ }
9
+ export {
10
+ vite_default as default
11
+ };
@@ -0,0 +1 @@
1
+ {"type":"module"}