@isograph/react 0.0.0-main-3cb9ae33 → 0.0.0-main-3247c783

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.
@@ -1,7 +1,4 @@
1
- import { ItemCleanupPair } from '@isograph/disposable-types';
2
1
  import { FragmentReference } from '../FragmentReference';
3
- import { DataId } from '../IsographEnvironment';
4
- export declare function useClientSideDefer<TValue>([id, loader]: [
5
- DataId,
6
- () => ItemCleanupPair<FragmentReference<any, TValue>>
7
- ]): FragmentReference<any, TValue>;
2
+ import { LoadableField } from '../reader';
3
+ export declare function useClientSideDefer<TResult>(loadableField: LoadableField<void, TResult>): FragmentReference<any, TResult>;
4
+ export declare function useClientSideDefer<TArgs, TResult>(loadableField: LoadableField<TArgs, TResult>, args: TArgs): FragmentReference<any, TResult>;
@@ -5,7 +5,9 @@ const IsographEnvironmentProvider_1 = require("../IsographEnvironmentProvider");
5
5
  const cache_1 = require("../cache");
6
6
  const react_disposable_state_1 = require("@isograph/react-disposable-state");
7
7
  // TODO allow the user to pass props somehow
8
- function useClientSideDefer([id, loader]) {
8
+ function useClientSideDefer(loadableField, args) {
9
+ // @ts-expect-error args is missing iff it has the type void
10
+ const [id, loader] = loadableField(args);
9
11
  const environment = (0, IsographEnvironmentProvider_1.useIsographEnvironment)();
10
12
  const cache = (0, cache_1.getOrCreateCache)(environment, id, loader);
11
13
  const fragmentReference = (0, react_disposable_state_1.useLazyDisposableState)(cache).state;
package/dist/read.js CHANGED
@@ -155,8 +155,8 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, mutab
155
155
  const allowedVariables = refetchQuery.allowedVariables;
156
156
  // Second, we allow the user to call the resolver, which will ultimately
157
157
  // use the resolver reader AST to get the resolver parameters.
158
- target[field.alias] = [
159
- // DataId
158
+ target[field.alias] = (_args) => [
159
+ // Stable id
160
160
  root + '__' + field.name,
161
161
  // Fetcher
162
162
  field.refetchReaderArtifact.resolver(environment, refetchQueryArtifact, data.data, filterVariables(variables, allowedVariables), root, field.resolverReaderArtifact, field.usedRefetchQueries.map((id) => nestedRefetchQueries[id])),
package/dist/reader.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { ItemCleanupPair } from '@isograph/disposable-types';
2
+ import { Factory } from '@isograph/disposable-types';
3
3
  import { FragmentReference } from './FragmentReference';
4
4
  import { ComponentOrFieldName, DataId, IsographEnvironment } from './IsographEnvironment';
5
5
  import { RefetchQueryNormalizationArtifact, RefetchQueryNormalizationArtifactWrapper } from './entrypoint';
@@ -57,7 +57,6 @@ export type ReaderImperativelyLoadedField = {
57
57
  readonly name: string;
58
58
  readonly usedRefetchQueries: number[];
59
59
  };
60
- export type LoadableField<T> = [
61
- string,
62
- () => ItemCleanupPair<FragmentReference<any, T>>
63
- ];
60
+ type StableId = string;
61
+ export type LoadableField<TArgs, TResult> = (args: TArgs) => [StableId, Factory<FragmentReference<any, TResult>>];
62
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isograph/react",
3
- "version": "0.0.0-main-3cb9ae33",
3
+ "version": "0.0.0-main-3247c783",
4
4
  "description": "Use Isograph with React",
5
5
  "homepage": "https://isograph.dev",
6
6
  "main": "dist/index.js",
@@ -16,8 +16,8 @@
16
16
  "prepack": "yarn run test && yarn run compile"
17
17
  },
18
18
  "dependencies": {
19
- "@isograph/disposable-types": "0.0.0-main-3cb9ae33",
20
- "@isograph/react-disposable-state": "0.0.0-main-3cb9ae33",
19
+ "@isograph/disposable-types": "0.0.0-main-3247c783",
20
+ "@isograph/react-disposable-state": "0.0.0-main-3247c783",
21
21
  "react": "^18.2.0"
22
22
  },
23
23
  "devDependencies": {
@@ -1,15 +1,25 @@
1
- import { ItemCleanupPair } from '@isograph/disposable-types';
2
1
  import { FragmentReference } from '../FragmentReference';
3
2
  import { useIsographEnvironment } from '../IsographEnvironmentProvider';
4
3
  import { getOrCreateCache } from '../cache';
5
4
  import { useLazyDisposableState } from '@isograph/react-disposable-state';
6
- import { DataId } from '../IsographEnvironment';
5
+ import { LoadableField } from '../reader';
6
+
7
+ export function useClientSideDefer<TResult>(
8
+ loadableField: LoadableField<void, TResult>,
9
+ ): FragmentReference<any, TResult>;
10
+
11
+ export function useClientSideDefer<TArgs, TResult>(
12
+ loadableField: LoadableField<TArgs, TResult>,
13
+ args: TArgs,
14
+ ): FragmentReference<any, TResult>;
7
15
 
8
16
  // TODO allow the user to pass props somehow
9
- export function useClientSideDefer<TValue>([id, loader]: [
10
- DataId,
11
- () => ItemCleanupPair<FragmentReference<any, TValue>>,
12
- ]): FragmentReference<any, TValue> {
17
+ export function useClientSideDefer<TArgs, TResult>(
18
+ loadableField: LoadableField<TArgs, TResult>,
19
+ args?: TArgs,
20
+ ): FragmentReference<any, TResult> {
21
+ // @ts-expect-error args is missing iff it has the type void
22
+ const [id, loader] = loadableField(args);
13
23
  const environment = useIsographEnvironment();
14
24
  const cache = getOrCreateCache(environment, id, loader);
15
25
 
package/src/read.ts CHANGED
@@ -222,8 +222,8 @@ function readData<TReadFromStore>(
222
222
 
223
223
  // Second, we allow the user to call the resolver, which will ultimately
224
224
  // use the resolver reader AST to get the resolver parameters.
225
- target[field.alias] = [
226
- // DataId
225
+ target[field.alias] = (_args: void) => [
226
+ // Stable id
227
227
  root + '__' + field.name,
228
228
  // Fetcher
229
229
  field.refetchReaderArtifact.resolver(
package/src/reader.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ItemCleanupPair } from '@isograph/disposable-types';
1
+ import { Factory } from '@isograph/disposable-types';
2
2
  import { FragmentReference } from './FragmentReference';
3
3
  import {
4
4
  ComponentOrFieldName,
@@ -119,7 +119,16 @@ export type ReaderImperativelyLoadedField = {
119
119
  readonly usedRefetchQueries: number[];
120
120
  };
121
121
 
122
- export type LoadableField<T> = [
123
- string,
124
- () => ItemCleanupPair<FragmentReference<any, T>>,
125
- ];
122
+ type StableId = string;
123
+ /// Why is LoadableField the way it is? Let's work backwards.
124
+ ///
125
+ /// We ultimately need a stable id (for deduplication) and a way to produce a
126
+ /// FragmentReference (i.e. a Factory). However, this stable id depends on the
127
+ /// arguments that we pass in, hence we get the current form of LoadableField.
128
+ ///
129
+ /// Passing TArgs to the LoadableField should be cheap and do no "actual" work,
130
+ /// except to stringify the args or whatnot. Calling the factory can be
131
+ /// expensive. For example, doing so will probably trigger a network request.
132
+ export type LoadableField<TArgs, TResult> = (
133
+ args: TArgs,
134
+ ) => [StableId, Factory<FragmentReference<any, TResult>>];