@warp-drive/react 5.9.0-beta.0 → 5.9.0-beta.2
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/CHANGELOG.md +38 -0
- package/dist/index.d.ts +180 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +216 -251
- package/dist/index.js.map +1 -0
- package/dist/install.d.ts +21 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +90 -94
- package/dist/install.js.map +1 -0
- package/dist/reactive-context-DhUW_l--.js +122 -0
- package/dist/reactive-context-DhUW_l--.js.map +1 -0
- package/dist/unpkg/dev/index.js +260 -299
- package/dist/unpkg/dev/index.js.map +1 -0
- package/dist/unpkg/dev/install.js +82 -92
- package/dist/unpkg/dev/install.js.map +1 -0
- package/dist/unpkg/dev/reactive-context-Ax2U-96G.js +218 -0
- package/dist/unpkg/dev/reactive-context-Ax2U-96G.js.map +1 -0
- package/dist/unpkg/dev-deprecated/index.js +260 -299
- package/dist/unpkg/dev-deprecated/index.js.map +1 -0
- package/dist/unpkg/dev-deprecated/install.js +82 -92
- package/dist/unpkg/dev-deprecated/install.js.map +1 -0
- package/dist/unpkg/dev-deprecated/reactive-context-B-pn7tS7.js +218 -0
- package/dist/unpkg/dev-deprecated/reactive-context-B-pn7tS7.js.map +1 -0
- package/dist/unpkg/prod/index.js +199 -226
- package/dist/unpkg/prod/index.js.map +1 -0
- package/dist/unpkg/prod/install.js +56 -48
- package/dist/unpkg/prod/install.js.map +1 -0
- package/dist/unpkg/prod/reactive-context-eAEvPuqb.js +92 -0
- package/dist/unpkg/prod/reactive-context-eAEvPuqb.js.map +1 -0
- package/dist/unpkg/prod-deprecated/index.js +199 -226
- package/dist/unpkg/prod-deprecated/index.js.map +1 -0
- package/dist/unpkg/prod-deprecated/install.js +56 -48
- package/dist/unpkg/prod-deprecated/install.js.map +1 -0
- package/dist/unpkg/prod-deprecated/reactive-context-eAEvPuqb.js +92 -0
- package/dist/unpkg/prod-deprecated/reactive-context-eAEvPuqb.js.map +1 -0
- package/package.json +25 -33
- package/declarations/-private/reactive-context.d.ts +0 -18
- package/declarations/-private/request.d.ts +0 -142
- package/declarations/-private/store-provider.d.ts +0 -19
- package/declarations/index.d.ts +0 -7
- package/declarations/install.d.ts +0 -3
- package/dist/reactive-context-ClTRYXie.js +0 -154
- package/dist/unpkg/dev/reactive-context-B815u0_c.js +0 -290
- package/dist/unpkg/dev-deprecated/reactive-context-DMgQ7YV_.js +0 -290
- package/dist/unpkg/prod/reactive-context-DKimDkR3.js +0 -110
- package/dist/unpkg/prod-deprecated/reactive-context-DKimDkR3.js +0 -110
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { createContext, useMemo, useSyncExternalStore } from "react";
|
|
2
|
+
import { Signal } from "signal-polyfill";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/-private/reactive-context.tsx
|
|
6
|
+
let nextFlush = null;
|
|
7
|
+
let watchers = [];
|
|
8
|
+
let watcherId = 0;
|
|
9
|
+
function clearWatcher(state) {
|
|
10
|
+
state.watcher.unwatch(...Signal.subtle.introspectSources(state.watcher));
|
|
11
|
+
}
|
|
12
|
+
function flush(state) {
|
|
13
|
+
state.pending = false;
|
|
14
|
+
if (state.destroyed) {
|
|
15
|
+
state.snapshot = null;
|
|
16
|
+
clearWatcher(state);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
state.snapshot = { watcher: state.watcher };
|
|
20
|
+
if (state.notifyReact) state.notifyReact();
|
|
21
|
+
state.watcher.watch();
|
|
22
|
+
}
|
|
23
|
+
function _createWatcher() {
|
|
24
|
+
const state = {
|
|
25
|
+
watcherId: watcherId++,
|
|
26
|
+
pending: false,
|
|
27
|
+
destroyed: false,
|
|
28
|
+
notifyReact: null,
|
|
29
|
+
watcher: null,
|
|
30
|
+
snapshot: null
|
|
31
|
+
};
|
|
32
|
+
state.watcher = new Signal.subtle.Watcher((...args) => {
|
|
33
|
+
if (!state.pending && !state.destroyed) {
|
|
34
|
+
watchers.push(state);
|
|
35
|
+
state.pending = true;
|
|
36
|
+
if (!nextFlush) nextFlush = new Promise((resolve) => {
|
|
37
|
+
queueMicrotask(() => {
|
|
38
|
+
queueMicrotask(() => {
|
|
39
|
+
queueMicrotask(() => {
|
|
40
|
+
watchers.forEach(flush);
|
|
41
|
+
watchers = [];
|
|
42
|
+
nextFlush = null;
|
|
43
|
+
resolve();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
} else if (state.destroyed) {
|
|
49
|
+
state.snapshot = null;
|
|
50
|
+
clearWatcher(state);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
state.watcher.watch();
|
|
54
|
+
state.snapshot = { watcher: state.watcher };
|
|
55
|
+
return state;
|
|
56
|
+
}
|
|
57
|
+
function useWatcher() {
|
|
58
|
+
const state = useMemo(_createWatcher, []);
|
|
59
|
+
return useSyncExternalStore((notifyChanged) => {
|
|
60
|
+
state.destroyed = false;
|
|
61
|
+
state.notifyReact = notifyChanged;
|
|
62
|
+
state.watcher.watch();
|
|
63
|
+
return () => {
|
|
64
|
+
state.destroyed = true;
|
|
65
|
+
state.notifyReact = null;
|
|
66
|
+
};
|
|
67
|
+
}, () => state.snapshot);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @category Contexts
|
|
71
|
+
*/
|
|
72
|
+
const WatcherContext = /*#__PURE__*/ createContext(null);
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @category Components
|
|
76
|
+
*/
|
|
77
|
+
function ReactiveContext({ children }) {
|
|
78
|
+
const watcher = useWatcher();
|
|
79
|
+
/**
|
|
80
|
+
* Unlike other frameworks, React does not have a built-in way to provide
|
|
81
|
+
* a context value other than by rendering an extra component.
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
return /*#__PURE__*/ jsx(WatcherContext, {
|
|
85
|
+
value: watcher,
|
|
86
|
+
children
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
export { WatcherContext as n, ReactiveContext as t };
|
|
92
|
+
//# sourceMappingURL=reactive-context-eAEvPuqb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactive-context-eAEvPuqb.js","names":["createContext","useSyncExternalStore","useMemo","Signal","jsx","_jsx","nextFlush","watchers","watcherId","clearWatcher","state","watcher","unwatch","subtle","introspectSources","flush","pending","destroyed","snapshot","notifyReact","watch","_createWatcher","id","Watcher","args","push","Promise","resolve","queueMicrotask","forEach","useWatcher","notifyChanged","WatcherContext","ReactiveContext","children","value"],"sources":["../../../src/-private/reactive-context.tsx"],"sourcesContent":["import { createContext, type JSX, type ReactNode, useSyncExternalStore, type Context, useMemo } from \"react\";\nimport { Signal } from \"signal-polyfill\";\n\nimport { LOG_REACT_SIGNAL_INTEGRATION } from \"@warp-drive/core/build-config/debugging\";\n\nlet nextFlush: Promise<void> | null = null;\nlet watchers: WatcherState[] = [];\nlet watcherId = 0;\n\ninterface WatcherState {\n watcherId: number;\n pending: boolean;\n destroyed: boolean;\n notifyReact: (() => void) | null;\n watcher: Signal.subtle.Watcher;\n\n // the extra wrapper returned here ensures that the context value for the watcher\n // changes causing a re-render when the watcher is updated.\n snapshot: { watcher: Signal.subtle.Watcher } | null;\n}\n\nfunction clearWatcher(state: WatcherState) {\n state.watcher.unwatch(...Signal.subtle.introspectSources(state.watcher));\n}\n\nfunction flush(state: WatcherState) {\n state.pending = false;\n if (state.destroyed) {\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n // eslint-disable-next-line no-console\n console.log(`[WarpDrive] Detected Watcher Destroyed During Notify Flush, clearing signals`);\n }\n state.snapshot = null;\n clearWatcher(state);\n return;\n }\n\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n /* eslint-disable no-console */\n console.log(`[WarpDrive] Notifying React That WatcherContext:${state.watcherId} Has Updated`);\n console.log(\"all signals\", new Set(Signal.subtle.introspectSources(state.watcher)));\n console.log(\"dirty signals\", new Set(state.watcher.getPending()));\n /* eslint-enable no-console */\n }\n\n // any time signals have changed, we notify React that our store has updated\n state.snapshot = { watcher: state.watcher };\n if (state.notifyReact) state.notifyReact();\n\n // tell the Watcher to start watching for changes again\n // by signaling that notifications have been flushed.\n state.watcher.watch();\n}\n\nfunction _createWatcher() {\n const id = watcherId++;\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n // eslint-disable-next-line no-console\n console.log(`[WarpDrive] Creating a WatcherContext:${id}`);\n }\n const state: WatcherState = {\n watcherId: id,\n pending: false,\n destroyed: false,\n notifyReact: null as (() => void) | null,\n watcher: null as unknown as Signal.subtle.Watcher,\n\n // the extra wrapper returned here ensures that the context value for the watcher\n // changes causing a re-render when the watcher is updated.\n snapshot: null as { watcher: Signal.subtle.Watcher } | null,\n };\n\n state.watcher = new Signal.subtle.Watcher((...args) => {\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n // eslint-disable-next-line no-console\n console.log(`watcher ${state.watcherId} notified`, args, state.watcher);\n }\n if (!state.pending && !state.destroyed) {\n watchers.push(state);\n state.pending = true;\n\n if (!nextFlush) {\n nextFlush = new Promise((resolve) => {\n queueMicrotask(() => {\n queueMicrotask(() => {\n queueMicrotask(() => {\n watchers.forEach(flush);\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n // eslint-disable-next-line no-console\n console.log(\n \"Flushed watcher:\",\n watchers.map((w) => w.watcherId)\n );\n }\n watchers = [];\n nextFlush = null;\n\n resolve();\n });\n });\n });\n });\n }\n } else if (state.destroyed) {\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n // eslint-disable-next-line no-console\n console.log(`[WarpDrive] Detected Watcher Destroyed During Notify, clearing signals`);\n }\n // if we are destroyed, we clear the watcher signals\n // so that it does not continue to watch for changes.\n state.snapshot = null;\n clearWatcher(state);\n }\n });\n\n // The watcher won't begin watching until we call `watcher.watch()`\n state.watcher.watch();\n state.snapshot = { watcher: state.watcher };\n\n return state;\n}\n\nexport function useWatcher(): { watcher: Signal.subtle.Watcher } | null {\n const state = useMemo(_createWatcher, []);\n\n return useSyncExternalStore(\n (notifyChanged: () => void) => {\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n // eslint-disable-next-line no-console\n console.log(`[WarpDrive] Subscribing to Watcher`);\n }\n state.destroyed = false;\n state.notifyReact = notifyChanged;\n\n // The watcher won't begin watching until we call `watcher.watch()`\n state.watcher.watch();\n\n return () => {\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n // eslint-disable-next-line no-console\n console.log(`[WarpDrive] Deactivating Watcher Subscription`);\n }\n state.destroyed = true;\n state.notifyReact = null;\n };\n },\n () => state.snapshot\n );\n}\n\n/**\n * @category Contexts\n */\nexport const WatcherContext: Context<{\n /**\n * The `Signal.subtle.Watcher` used to observe signal changes for the nearest {@link ReactiveContext}.\n */\n watcher: Signal.subtle.Watcher;\n} | null> = createContext<{\n watcher: Signal.subtle.Watcher;\n} | null>(null);\n\n/**\n *\n * @category Components\n */\nexport function ReactiveContext({ children }: { children: ReactNode }): JSX.Element {\n const watcher = useWatcher();\n /**\n * Unlike other frameworks, React does not have a built-in way to provide\n * a context value other than by rendering an extra component.\n *\n */\n return <WatcherContext value={watcher}>{children}</WatcherContext>;\n}\n"],"mappings":";;;;;AAKA,IAAIM,YAAkC;AACtC,IAAIC,WAA2B,CAAA;AAC/B,IAAIC,YAAY;AAchB,SAASC,aAAaC,OAAqB;CACzCA,MAAMC,QAAQC,QAAQ,GAAGT,OAAOU,OAAOC,kBAAkBJ,MAAMC,OAAO,CAAC;AACzE;AAEA,SAASI,MAAML,OAAqB;CAClCA,MAAMM,UAAU;CAChB,IAAIN,MAAMO,WAAW;EAKnBP,MAAMQ,WAAW;EACjBT,aAAaC,KAAK;EAClB;CACF;CAWAA,MAAMQ,WAAW,EAAEP,SAASD,MAAMC,QAAQ;CAC1C,IAAID,MAAMS,aAAaT,MAAMS,YA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|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { createRequestSubscription } from '@warp-drive/core/reactive';
|
|
7
|
-
import { DISPOSE, signal } from '@warp-drive/core/signals/-leaked';
|
|
8
|
-
import '@warp-drive/core/request';
|
|
9
|
-
const StoreContext = /*#__PURE__*/createContext(null);
|
|
1
|
+
import { n as WatcherContext, t as ReactiveContext } from "./reactive-context-eAEvPuqb.js";
|
|
2
|
+
import { createContext, use, useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
4
|
+
import { createRequestSubscription } from "@warp-drive/core/reactive";
|
|
5
|
+
import { DISPOSE, signal } from "@warp-drive/core/signals/-leaked";
|
|
10
6
|
|
|
7
|
+
//#region src/-private/store-provider.tsx
|
|
11
8
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
* @category Contexts
|
|
10
|
+
*/
|
|
11
|
+
const StoreContext = /*#__PURE__*/ createContext(null);
|
|
12
|
+
/**
|
|
13
|
+
* @category Hooks
|
|
14
|
+
*/
|
|
14
15
|
function useStore() {
|
|
15
|
-
|
|
16
|
-
return store;
|
|
16
|
+
return use(StoreContext);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
* @category Components
|
|
20
|
+
*/
|
|
21
21
|
function StoreProvider($props) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const store = useMemo(() => "store" in $props ? $props.store : new $props.Store(), ["store" in $props ? $props.store : $props.Store]);
|
|
23
|
+
return /*#__PURE__*/ jsx(StoreContext, {
|
|
24
|
+
value: store,
|
|
25
|
+
children: $props.children
|
|
26
|
+
});
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region ../../node_modules/.pnpm/decorat_5d4eca388601a94e7fbc656401b751d1/node_modules/decorator-transforms/dist/runtime--fcdnjmJ.js
|
|
31
|
+
const deferred = /* @__PURE__ */ new WeakMap();
|
|
29
32
|
function deferDecorator(proto, prop, desc) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
let map = deferred.get(proto);
|
|
34
|
+
if (!map) {
|
|
35
|
+
map = /* @__PURE__ */ new Map();
|
|
36
|
+
deferred.set(proto, map);
|
|
37
|
+
}
|
|
38
|
+
map.set(prop, desc);
|
|
36
39
|
}
|
|
37
40
|
function findDeferredDecorator(target, prop) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
cursor = cursor.prototype;
|
|
46
|
-
}
|
|
41
|
+
var _a;
|
|
42
|
+
let cursor = target.prototype;
|
|
43
|
+
while (cursor) {
|
|
44
|
+
let desc = (_a = deferred.get(cursor)) == null ? void 0 : _a.get(prop);
|
|
45
|
+
if (desc) return desc;
|
|
46
|
+
cursor = Object.getPrototypeOf(cursor);
|
|
47
|
+
}
|
|
47
48
|
}
|
|
48
49
|
function decorateFieldV2(prototype, prop, decorators, initializer) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
desc = decorator(prototype, prop, desc) || desc;
|
|
60
|
-
}
|
|
61
|
-
if (desc.initializer === void 0) {
|
|
62
|
-
Object.defineProperty(prototype, prop, desc);
|
|
63
|
-
} else {
|
|
64
|
-
deferDecorator(prototype, prop, desc);
|
|
65
|
-
}
|
|
50
|
+
let desc = {
|
|
51
|
+
configurable: true,
|
|
52
|
+
enumerable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
initializer: null
|
|
55
|
+
};
|
|
56
|
+
if (initializer) desc.initializer = initializer;
|
|
57
|
+
for (let decorator of decorators) desc = decorator(prototype, prop, desc) || desc;
|
|
58
|
+
if (desc.initializer === void 0) Object.defineProperty(prototype, prop, desc);
|
|
59
|
+
else deferDecorator(prototype, prop, desc);
|
|
66
60
|
}
|
|
67
61
|
function initializeDeferredDecorator(target, prop) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const IdleBlockMissingError = new Error("No idle block provided for <Request> component, and no query or request was provided.");
|
|
79
|
-
class ReactiveArgs {
|
|
80
|
-
static {
|
|
81
|
-
decorateFieldV2(this.prototype, "request", [signal]);
|
|
82
|
-
}
|
|
83
|
-
#request = (initializeDeferredDecorator(this, "request"), void 0);
|
|
84
|
-
static {
|
|
85
|
-
decorateFieldV2(this.prototype, "query", [signal]);
|
|
86
|
-
}
|
|
87
|
-
#query = (initializeDeferredDecorator(this, "query"), void 0);
|
|
88
|
-
static {
|
|
89
|
-
decorateFieldV2(this.prototype, "autorefresh", [signal]);
|
|
90
|
-
}
|
|
91
|
-
#autorefresh = (initializeDeferredDecorator(this, "autorefresh"), void 0);
|
|
92
|
-
static {
|
|
93
|
-
decorateFieldV2(this.prototype, "autorefreshThreshold", [signal]);
|
|
94
|
-
}
|
|
95
|
-
#autorefreshThreshold = (initializeDeferredDecorator(this, "autorefreshThreshold"), void 0);
|
|
96
|
-
static {
|
|
97
|
-
decorateFieldV2(this.prototype, "autorefreshBehavior", [signal]);
|
|
98
|
-
}
|
|
99
|
-
#autorefreshBehavior = (initializeDeferredDecorator(this, "autorefreshBehavior"), void 0);
|
|
62
|
+
let desc = findDeferredDecorator(target.constructor, prop);
|
|
63
|
+
if (desc) Object.defineProperty(target, prop, {
|
|
64
|
+
enumerable: desc.enumerable,
|
|
65
|
+
configurable: desc.configurable,
|
|
66
|
+
writable: desc.writable,
|
|
67
|
+
value: desc.initializer ? desc.initializer.call(target) : void 0
|
|
68
|
+
});
|
|
100
69
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/-private/request.tsx
|
|
73
|
+
const IdleBlockMissingError = /* @__PURE__ */ new Error("No idle block provided for <Request> component, and no query or request was provided.");
|
|
74
|
+
var ReactiveArgs = class {
|
|
75
|
+
static {
|
|
76
|
+
decorateFieldV2(this.prototype, "request", [signal]);
|
|
77
|
+
}
|
|
78
|
+
#request = (initializeDeferredDecorator(this, "request"), void 0);
|
|
79
|
+
static {
|
|
80
|
+
decorateFieldV2(this.prototype, "query", [signal]);
|
|
81
|
+
}
|
|
82
|
+
#query = (initializeDeferredDecorator(this, "query"), void 0);
|
|
83
|
+
static {
|
|
84
|
+
decorateFieldV2(this.prototype, "autorefresh", [signal]);
|
|
85
|
+
}
|
|
86
|
+
#autorefresh = (initializeDeferredDecorator(this, "autorefresh"), void 0);
|
|
87
|
+
static {
|
|
88
|
+
decorateFieldV2(this.prototype, "autorefreshThreshold", [signal]);
|
|
89
|
+
}
|
|
90
|
+
#autorefreshThreshold = (initializeDeferredDecorator(this, "autorefreshThreshold"), void 0);
|
|
91
|
+
static {
|
|
92
|
+
decorateFieldV2(this.prototype, "autorefreshBehavior", [signal]);
|
|
93
|
+
}
|
|
94
|
+
#autorefreshBehavior = (initializeDeferredDecorator(this, "autorefreshBehavior"), void 0);
|
|
95
|
+
};
|
|
96
|
+
const DefaultChrome = ({ children }) => {
|
|
97
|
+
return /*#__PURE__*/ jsx(Fragment, { children });
|
|
107
98
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Throws the given error. Used internally to rethrow request errors that
|
|
101
|
+
* are not otherwise handled by a provided error/cancelled block.
|
|
102
|
+
*
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
function Throw({ error }) {
|
|
106
|
+
throw error;
|
|
112
107
|
}
|
|
113
|
-
|
|
114
108
|
/**
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
109
|
+
* The `<Request />` component is a powerful tool for managing data fetching and
|
|
110
|
+
* state in your React application. It provides a declarative approach to reactive
|
|
111
|
+
* control-flow for managing requests and state in your application.
|
|
112
|
+
*
|
|
113
|
+
* The `<Request />` component is ideal for handling "boundaries", outside which some
|
|
114
|
+
* state is still allowed to be unresolved and within which it MUST be resolved.
|
|
115
|
+
*
|
|
116
|
+
* ## Request States
|
|
117
|
+
*
|
|
118
|
+
* `<Request />` has five states, only one of which will be active and rendered at a time.
|
|
119
|
+
*
|
|
120
|
+
* - `idle`: The component is waiting to be given a request to monitor
|
|
121
|
+
* - `loading`: The request is in progress
|
|
122
|
+
* - `error`: The request failed
|
|
123
|
+
* - `content`: The request succeeded
|
|
124
|
+
* - `cancelled`: The request was cancelled
|
|
125
|
+
*
|
|
126
|
+
* Additionally, the `content` state has a `refresh` method that can be used to
|
|
127
|
+
* refresh the request in the background, which is available as a sub-state of
|
|
128
|
+
* the `content` state.
|
|
129
|
+
*
|
|
130
|
+
* ### Example Usage
|
|
131
|
+
*
|
|
132
|
+
* ```tsx
|
|
133
|
+
* import { Request } from "@warp-drive/react";
|
|
134
|
+
*
|
|
135
|
+
* export function UserPreview($props: { id: string | null }) {
|
|
136
|
+
* return (
|
|
137
|
+
* <Request
|
|
138
|
+
* query={findRecord('user', $props.id)}
|
|
139
|
+
* states={{
|
|
140
|
+
* idle: () => <div>Waiting for User Selection</div>,
|
|
141
|
+
* loading: ({ state }) => <div>Loading user data...</div>,
|
|
142
|
+
* cancelled: ({ error, features }) => (
|
|
143
|
+
* <div>
|
|
144
|
+
* <p>Request Cancelled</p>
|
|
145
|
+
* <p><button onClick={features.retry}>Start Again?</button></p>
|
|
146
|
+
* </div>
|
|
147
|
+
* ),
|
|
148
|
+
* error: ({ error, features }) => (
|
|
149
|
+
* <div>
|
|
150
|
+
* <p>Error: {error.message}</p>
|
|
151
|
+
* <p><button onClick={features.retry}>Try Again?</button></p>
|
|
152
|
+
* </div>
|
|
153
|
+
* ),
|
|
154
|
+
* content: ({ result, features }) => (
|
|
155
|
+
* <div>
|
|
156
|
+
* <h2>User Details</h2>
|
|
157
|
+
* <p>ID: {result.id}</p>
|
|
158
|
+
* <p>Name: {result.name}</p>
|
|
159
|
+
* </div>
|
|
160
|
+
* ),
|
|
161
|
+
* }}
|
|
162
|
+
* />
|
|
163
|
+
* );
|
|
164
|
+
* }
|
|
165
|
+
*
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @category Components
|
|
169
|
+
*/
|
|
176
170
|
function Request($props) {
|
|
177
|
-
|
|
178
|
-
children: /*#__PURE__*/jsx(InternalRequest, {
|
|
179
|
-
...$props
|
|
180
|
-
})
|
|
181
|
-
});
|
|
171
|
+
return /*#__PURE__*/ jsx(ReactiveContext, { children: /*#__PURE__*/ jsx(InternalRequest, { ...$props }) });
|
|
182
172
|
}
|
|
183
173
|
function isStrictModeRender() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
// in debug we need to skip every second invocation
|
|
187
|
-
|
|
188
|
-
return false;
|
|
174
|
+
useRef(0);
|
|
175
|
+
return false;
|
|
189
176
|
}
|
|
190
177
|
function InternalRequest($props) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}) : state.reqState.isLoading ? slots.loading ? /*#__PURE__*/jsx(slots.loading, {
|
|
233
|
-
state: state.reqState.loadingState
|
|
234
|
-
}) : '' : state.reqState.isCancelled && slots.cancelled ? /*#__PURE__*/jsx(slots.cancelled, {
|
|
235
|
-
error: state.reqState.reason,
|
|
236
|
-
features: state.errorFeatures
|
|
237
|
-
}) : state.reqState.isError && slots.error ? /*#__PURE__*/jsx(slots.error, {
|
|
238
|
-
error: state.reqState.reason,
|
|
239
|
-
features: state.errorFeatures
|
|
240
|
-
}) : state.reqState.isSuccess ? slots.content ? /*#__PURE__*/jsx(slots.content, {
|
|
241
|
-
result: state.reqState.value,
|
|
242
|
-
features: state.contentFeatures
|
|
243
|
-
}) : /*#__PURE__*/jsx(Throw, {
|
|
244
|
-
error: new Error('No content block provided for <Request> component.')
|
|
245
|
-
}) : !state.reqState.isCancelled ? /*#__PURE__*/jsx(Throw, {
|
|
246
|
-
error: state.reqState.reason
|
|
247
|
-
}) : '' // never
|
|
248
|
-
});
|
|
178
|
+
isStrictModeRender();
|
|
179
|
+
const store = $props.store ?? useStore();
|
|
180
|
+
const Chrome = $props.chrome ?? DefaultChrome;
|
|
181
|
+
const sink = useRef(null);
|
|
182
|
+
const args = useRef(null);
|
|
183
|
+
if (!args.current) args.current = new ReactiveArgs();
|
|
184
|
+
Object.assign(args.current, $props);
|
|
185
|
+
if (sink.current && (sink.current.store !== store || $props.subscription)) {
|
|
186
|
+
sink.current[DISPOSE]();
|
|
187
|
+
sink.current = null;
|
|
188
|
+
}
|
|
189
|
+
if (!sink.current && !$props.subscription) sink.current = createRequestSubscription(store, args.current);
|
|
190
|
+
const initialized = useRef(null);
|
|
191
|
+
const effect = () => {
|
|
192
|
+
if (sink.current && (!initialized.current || initialized.current.disposable !== sink.current)) initialized.current = {
|
|
193
|
+
disposable: sink.current,
|
|
194
|
+
dispose: () => {
|
|
195
|
+
sink.current?.[DISPOSE]();
|
|
196
|
+
initialized.current = null;
|
|
197
|
+
sink.current = null;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
return sink.current ? initialized.current.dispose : void 0;
|
|
201
|
+
};
|
|
202
|
+
useEffect(effect, [sink.current]);
|
|
203
|
+
const state = $props.subscription ?? sink.current;
|
|
204
|
+
const slots = $props.states;
|
|
205
|
+
return /*#__PURE__*/ jsx(Chrome, {
|
|
206
|
+
state: state.isIdle ? null : state.reqState,
|
|
207
|
+
features: state.contentFeatures,
|
|
208
|
+
children: state.isIdle && slots.idle ? /*#__PURE__*/ jsx(slots.idle, {}) : state.isIdle ? /*#__PURE__*/ jsx(Throw, { error: IdleBlockMissingError }) : state.reqState.isLoading ? slots.loading ? /*#__PURE__*/ jsx(slots.loading, { state: state.reqState.loadingState }) : "" : state.reqState.isCancelled && slots.cancelled ? /*#__PURE__*/ jsx(slots.cancelled, {
|
|
209
|
+
error: state.reqState.reason,
|
|
210
|
+
features: state.errorFeatures
|
|
211
|
+
}) : state.reqState.isError && slots.error ? /*#__PURE__*/ jsx(slots.error, {
|
|
212
|
+
error: state.reqState.reason,
|
|
213
|
+
features: state.errorFeatures
|
|
214
|
+
}) : state.reqState.isSuccess ? slots.content ? /*#__PURE__*/ jsx(slots.content, {
|
|
215
|
+
result: state.reqState.value,
|
|
216
|
+
features: state.contentFeatures
|
|
217
|
+
}) : /*#__PURE__*/ jsx(Throw, { error: /* @__PURE__ */ new Error("No content block provided for <Request> component.") }) : !state.reqState.isCancelled ? /*#__PURE__*/ jsx(Throw, { error: state.reqState.reason }) : ""
|
|
218
|
+
});
|
|
249
219
|
}
|
|
250
|
-
|
|
220
|
+
|
|
221
|
+
//#endregion
|
|
222
|
+
export { ReactiveContext, Request, StoreProvider, Throw, WatcherContext, useStore };
|
|
223
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["createContext","use","useMemo","jsx","_jsx","StoreContext","useStore","store","StoreProvider","$props","Store","value","children","useEffect","useRef","createRequestSubscription","DISPOSE","signal","ReactiveContext","useStore","g","i","Fragment","_Fragment","jsx","_jsx","IdleBlockMissingError","Error","ReactiveArgs","prototype","request","query","autorefresh","autorefreshThreshold","autorefreshBehavior","DefaultChrome","children","Throw","error","Request","$props","InternalRequest","isStrictModeRender","count","isStrict","store","Chrome","chrome","sink","args","current","Object","assign","subscription","initialized","effect","disposable","dispose","undefined","maybeEffect","state","slots","states","isIdle","reqState","features","contentFeatures","idle","isLoading","loading","loadingState","isCancelled","cancelled","reason","errorFeatures","isError","isSuccess","content","result","value"],"sources":["../../../src/-private/store-provider.tsx","../../../../../node_modules/.pnpm/decorat_5d4eca388601a94e7fbc656401b751d1/node_modules/decorator-transforms/dist/runtime--fcdnjmJ.js","../../../src/-private/request.tsx"],"sourcesContent":["import type { JSX, ReactNode } from \"react\";\nimport { createContext, use, useMemo } from \"react\";\n\nimport type { Store } from \"@warp-drive/core\";\nimport { assert } from \"@warp-drive/core/build-config/macros\";\n\n/**\n * @category Contexts\n */\nconst StoreContext = createContext<Store | null>(null);\n\n/**\n * @category Hooks\n */\nexport function useStore(): Store {\n const store = use(StoreContext);\n assert(\n \"No Store provided via context. Please ensure you are using <StoreProvider> to provide a Store instance.\",\n store\n );\n return store;\n}\n\ntype WithExistingStore = { store: Store; children: ReactNode };\ntype WithNewStore = { Store: typeof Store; children: ReactNode };\n\n/**\n * @category Components\n */\nexport function StoreProvider($props: WithExistingStore | WithNewStore): JSX.Element {\n const store = useMemo(\n () => (\"store\" in $props ? $props.store : new $props.Store()),\n [\"store\" in $props ? $props.store : $props.Store]\n );\n\n return <StoreContext value={store}>{$props.children}</StoreContext>;\n}\n","const deferred = /* @__PURE__ */ new WeakMap();\nfunction deferDecorator(proto, prop, desc) {\n let map = deferred.get(proto);\n if (!map) {\n map = /* @__PURE__ */ new Map();\n deferred.set(proto, map);\n }\n map.set(prop, desc);\n}\nfunction findDeferredDecorator(target, prop) {\n var _a;\n let cursor = target.prototype;\n while (cursor) {\n let desc = (_a = deferred.get(cursor)) == null ? void 0 : _a.get(prop);\n if (desc) {\n return desc;\n }\n cursor = Object.getPrototypeOf(cursor);\n }\n}\nfunction decorateFieldV1(target, prop, decorators, initializer) {\n return decorateFieldV2(target.prototype, prop, decorators, initializer);\n}\nfunction decorateFieldV2(prototype, prop, decorators, initializer) {\n let desc = {\n configurable: true,\n enumerable: true,\n writable: true,\n initializer: null\n };\n if (initializer) {\n desc.initializer = initializer;\n }\n for (let decorator of decorators) {\n desc = decorator(prototype, prop, desc) || desc;\n }\n if (desc.initializer === void 0) {\n Object.defineProperty(prototype, prop, desc);\n } else {\n deferDecorator(prototype, prop, desc);\n }\n}\nfunction decorateMethodV1({ prototype }, prop, decorators) {\n return decorateMethodV2(prototype, prop, decorators);\n}\nfunction decorateMethodV2(prototype, prop, decorators) {\n const origDesc = Object.getOwnPropertyDescriptor(prototype, prop);\n let desc = { ...origDesc };\n for (let decorator of decorators) {\n desc = decorator(prototype, prop, desc) || desc;\n }\n if (desc.initializer !== void 0) {\n desc.value = desc.initializer ? desc.initializer.call(prototype) : void 0;\n desc.initializer = void 0;\n }\n Object.defineProperty(prototype, prop, desc);\n}\nfunction initializeDeferredDecorator(target, prop) {\n let desc = findDeferredDecorator(target.constructor, prop);\n if (desc) {\n Object.defineProperty(target, prop, {\n enumerable: desc.enumerable,\n configurable: desc.configurable,\n writable: desc.writable,\n value: desc.initializer ? desc.initializer.call(target) : void 0\n });\n }\n}\nfunction decorateClass(target, decorators) {\n return decorators.reduce(\n (accum, decorator) => decorator(accum) || accum,\n target\n );\n}\nfunction decoratePOJO(pojo, decorated) {\n for (let [type, prop, decorators] of decorated) {\n if (type === \"field\") {\n decoratePojoField(pojo, prop, decorators);\n } else {\n decorateMethodV2(pojo, prop, decorators);\n }\n }\n return pojo;\n}\nfunction decoratePojoField(pojo, prop, decorators) {\n let desc = {\n configurable: true,\n enumerable: true,\n writable: true,\n initializer: () => {\n var _a;\n return (_a = Object.getOwnPropertyDescriptor(pojo, prop)) == null ? void 0 : _a.value;\n }\n };\n for (let decorator of decorators) {\n desc = decorator(pojo, prop, desc) || desc;\n }\n if (desc.initializer) {\n desc.value = desc.initializer.call(pojo);\n delete desc.initializer;\n }\n Object.defineProperty(pojo, prop, desc);\n}\nconst runtime = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({\n __proto__: null,\n c: decorateClass,\n f: decorateFieldV1,\n g: decorateFieldV2,\n i: initializeDeferredDecorator,\n m: decorateMethodV1,\n n: decorateMethodV2,\n p: decoratePOJO\n}, Symbol.toStringTag, { value: \"Module\" }));\nexport {\n decorateFieldV1 as a,\n decorateFieldV2 as b,\n decorateMethodV1 as c,\n decorateClass as d,\n decorateMethodV2 as e,\n decoratePOJO as f,\n initializeDeferredDecorator as i,\n runtime as r\n};\n//# sourceMappingURL=runtime--fcdnjmJ.js.map\n","import type { JSX, ReactNode } from \"react\";\nimport { useEffect, useRef } from \"react\";\n\nimport type { StoreRequestInput } from \"@warp-drive/core\";\nimport { DEBUG } from \"@warp-drive/core/build-config/env\";\nimport {\n createRequestSubscription,\n type RequestLoadingState,\n type RequestState,\n type RequestSubscription,\n} from \"@warp-drive/core/reactive\";\nimport type { Future } from \"@warp-drive/core/request\";\nimport {\n type AutorefreshBehaviorCombos,\n DISPOSE,\n type RequestArgs,\n signal,\n type ContentFeatures,\n type RecoveryFeatures,\n type SubscriptionArgs,\n} from \"@warp-drive/core/signals/-leaked\";\nimport type { StructuredErrorDocument } from \"@warp-drive/core/types/request\";\n\nimport { ReactiveContext } from \"./reactive-context\";\nimport { useStore } from \"./store-provider\";\n\nconst IdleBlockMissingError = new Error(\n \"No idle block provided for <Request> component, and no query or request was provided.\"\n);\n\nclass ReactiveArgs<RT, E> implements SubscriptionArgs<RT, E> {\n @signal request?: Future<RT> | undefined | null;\n @signal query?: StoreRequestInput<RT> | undefined | null;\n @signal autorefresh?: AutorefreshBehaviorCombos | undefined;\n @signal autorefreshThreshold?: number | undefined;\n @signal autorefreshBehavior?: \"refresh\" | \"reload\" | \"policy\";\n}\n\ninterface ChromeComponentProps<RT> {\n children: ReactNode;\n state: RequestState | null;\n features: ContentFeatures<RT>;\n}\n\nconst DefaultChrome = <RT,>({ children }: ChromeComponentProps<RT>) => {\n return <>{children}</>;\n};\n\nexport interface RequestProps<RT, E> extends RequestArgs<RT, E> {\n chrome?: React.FC<ChromeComponentProps<RT>>;\n\n states: RequestStates<RT, E>;\n}\n\ninterface RequestStates<RT, E> {\n /**\n * The block to render when the component is idle and waiting to be given a request.\n *\n */\n idle?: React.FC<object>;\n\n /**\n * The block to render when the request is loading.\n *\n */\n loading?: React.FC<{ state: RequestLoadingState }>;\n\n /**\n * The block to render when the request was cancelled.\n *\n */\n cancelled?: React.FC<{\n /**\n * The Error the request rejected with.\n */\n error: StructuredErrorDocument<E>;\n /**\n * Utilities to assist in recovering from the error.\n */\n features: RecoveryFeatures;\n }>;\n\n /**\n * The block to render when the request failed. If this block is not provided,\n * the error will be rethrown.\n *\n * Thus it is required to provide an error block and proper error handling if\n * you do not want the error to crash the application.\n */\n error: React.FC<{\n /**\n * The Error the request rejected with.\n */\n error: StructuredErrorDocument<E>;\n /**\n * Utilities to assist in recovering from the error.\n */\n features: RecoveryFeatures;\n }>;\n\n /**\n * The block to render when the request succeeded.\n *\n */\n content: React.FC<{ result: RT; features: ContentFeatures<RT> }>;\n}\n\n/**\n * Throws the given error. Used internally to rethrow request errors that\n * are not otherwise handled by a provided error/cancelled block.\n *\n * @private\n */\nexport function Throw({ error }: { error: Error }): never {\n throw error;\n}\n\n/**\n * The `<Request />` component is a powerful tool for managing data fetching and\n * state in your React application. It provides a declarative approach to reactive\n * control-flow for managing requests and state in your application.\n *\n * The `<Request />` component is ideal for handling \"boundaries\", outside which some\n * state is still allowed to be unresolved and within which it MUST be resolved.\n *\n * ## Request States\n *\n * `<Request />` has five states, only one of which will be active and rendered at a time.\n *\n * - `idle`: The component is waiting to be given a request to monitor\n * - `loading`: The request is in progress\n * - `error`: The request failed\n * - `content`: The request succeeded\n * - `cancelled`: The request was cancelled\n *\n * Additionally, the `content` state has a `refresh` method that can be used to\n * refresh the request in the background, which is available as a sub-state of\n * the `content` state.\n *\n * ### Example Usage\n *\n * ```tsx\n * import { Request } from \"@warp-drive/react\";\n *\n * export function UserPreview($props: { id: string | null }) {\n * return (\n * <Request\n * query={findRecord('user', $props.id)}\n * states={{\n * idle: () => <div>Waiting for User Selection</div>,\n * loading: ({ state }) => <div>Loading user data...</div>,\n * cancelled: ({ error, features }) => (\n * <div>\n * <p>Request Cancelled</p>\n * <p><button onClick={features.retry}>Start Again?</button></p>\n * </div>\n * ),\n * error: ({ error, features }) => (\n * <div>\n * <p>Error: {error.message}</p>\n * <p><button onClick={features.retry}>Try Again?</button></p>\n * </div>\n * ),\n * content: ({ result, features }) => (\n * <div>\n * <h2>User Details</h2>\n * <p>ID: {result.id}</p>\n * <p>Name: {result.name}</p>\n * </div>\n * ),\n * }}\n * />\n * );\n * }\n *\n * ```\n *\n * @category Components\n */\nexport function Request<RT, E>($props: RequestProps<RT, E>): JSX.Element {\n return (\n <ReactiveContext>\n <InternalRequest {...$props} />\n </ReactiveContext>\n );\n}\n\nfunction isStrictModeRender(): boolean {\n const count = useRef<number>(0);\n\n // in debug we need to skip every second invocation\n if (DEBUG) {\n if (count.current++ % 2 === 1) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction InternalRequest<RT, E>($props: RequestProps<RT, E>): JSX.Element {\n const isStrict = isStrictModeRender();\n const store = $props.store ?? useStore();\n const Chrome = $props.chrome ?? DefaultChrome;\n const sink = useRef<RequestSubscription<RT, E> | null>(null);\n const args = useRef<SubscriptionArgs<RT, E> | null>(null);\n\n if (!args.current) {\n args.current = new ReactiveArgs<RT, E>();\n }\n Object.assign(args.current, $props);\n\n if (sink.current && (sink.current.store !== store || $props.subscription)) {\n sink.current[DISPOSE]();\n sink.current = null;\n }\n\n if (!sink.current && !$props.subscription) {\n sink.current = createRequestSubscription(store, args.current);\n }\n\n const initialized = useRef<null | {\n disposable: { [DISPOSE]: () => void } | null;\n dispose: () => void;\n }>(null);\n const effect = () => {\n if (sink.current && (!initialized.current || initialized.current.disposable !== sink.current)) {\n initialized.current = {\n disposable: sink.current,\n dispose: () => {\n sink.current?.[DISPOSE]();\n initialized.current = null;\n sink.current = null;\n },\n };\n }\n\n return sink.current ? initialized.current!.dispose : undefined;\n };\n let maybeEffect = effect;\n\n if (DEBUG) {\n if (isStrict) {\n maybeEffect = () => {\n if (initialized.current) {\n return effect();\n }\n return () => {\n // initialize our actual effect\n effect();\n // in strict mode we don't want to run the teardown\n // for the second invocation\n };\n };\n }\n }\n\n useEffect(maybeEffect, [sink.current]);\n\n const state = $props.subscription ?? sink.current!;\n const slots = $props.states;\n\n return (\n <Chrome state={state.isIdle ? null : state.reqState} features={state.contentFeatures}>\n {\n // prettier-ignore\n state.isIdle && slots.idle ? <slots.idle />\n : state.isIdle ? <Throw error={IdleBlockMissingError} />\n : state.reqState.isLoading ? slots.loading ? <slots.loading state={state.reqState.loadingState} /> : ''\n : state.reqState.isCancelled && slots.cancelled ? <slots.cancelled error={state.reqState.reason} features={state.errorFeatures} />\n : state.reqState.isError && slots.error ? <slots.error error={state.reqState.reason} features={state.errorFeatures} />\n : state.reqState.isSuccess ? slots.content ? <slots.content result={state.reqState.value} features={state.contentFeatures} /> : <Throw error={new Error('No content block provided for <Request> component.')} />\n : !state.reqState.isCancelled ? <Throw error={state.reqState.reason} />\n : '' // never\n }\n </Chrome>\n );\n}\n"],"x_google_ignoreList":[1],"mappings":";;;;;;;;;;AASA,MAAMK,eAAeL,4BAA4B,IAAI;;;;AAKrD,SAAgBM,WAAkB;CAMhC,OALcL,IAAII,YAKXE;AACT;;;;AAQA,SAAgBC,cAAcC,QAAuD;CACnF,MAAMF,QAAQL,cACL,WAAWO,SAASA,OAAOF,QAAQ,IAAIE,OAAOC,MAAM,GAC3D,CAAC,WAAWD,SAASA,OAAOF,QAAQE,OAAOC,KAAK,CAClD;CAEA,OAAON,kBAACC,cAAY;EAACM,OAAOJ;EAAMK,UAAEH,OAAOG;CAAQ,CAAe;AACpE;;;;ACpCA,MAAM,2BAA2B,IAAI,QAAQ;AAC7C,SAAS,eAAe,OAAO,MAAM,MAAM;CACzC,IAAI,MAAM,SAAS,IAAI,KAAK;CAC5B,IAAI,CAAC,KAAK;EACR,sBAAsB,IAAI,IAAI;EAC9B,SAAS,IAAI,OAAO,GAAG;CACzB;CACA,IAAI,IAAI,MAAM,IAAI;AACpB;AACA,SAAS,sBAAsB,QAAQ,MAAM;CAC3C,IAAI;CACJ,IAAI,SAAS,OAAO;CACpB,OAAO,QAAQ;EACb,IAAI,QAAQ,KAAK,SAAS,IAAI,MAAM,MAAM,OAAO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