@jigs.design/client 0.3.1 → 0.3.3

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/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { HeadersOption, Transport } from "./transport.js";
2
- import { Diagnostic, JigsErrorData, MutationResult, PageProps, Program, QueryResult, SessionBody, SessionEvent } from "@jigs.design/protocol";
2
+ import { Diagnostic, JigsErrorData, JsonValue, MutationResult, PageProps, Program, QueryResult, SessionBody, SessionEvent } from "@jigs.design/protocol";
3
3
  //#region src/client.d.ts
4
4
  interface CacheOptions {
5
5
  /**
@@ -46,8 +46,14 @@ export type ClientOptions = CacheOptions & ConfirmOptions & ({
46
46
  headers?: never;
47
47
  transport: Transport;
48
48
  });
49
- /** A page's program and its diagnostics, as the server compiled them. */
49
+ /** A page's program, its diagnostics and the data it keeps, as the server served them. */
50
50
  export interface PageData {
51
+ /**
52
+ * Provided data the page is drawn with, by slot: what the server kept
53
+ * with a saved page. Empty for a shipped page. Pass it to the view with
54
+ * the page's own slots: `data={{ ...page.data, ...own }}`.
55
+ */
56
+ data: Readonly<Record<string, JsonValue>>;
51
57
  /**
52
58
  * A saved page is compiled leniently, so these may hold errors: show a
53
59
  * notice beside the program when one is an error or a warning.
@@ -57,6 +63,8 @@ export interface PageData {
57
63
  }
58
64
  /** A page as `observePage` reports it. */
59
65
  export interface PageResult {
66
+ /** The provided data the page keeps; empty until a program arrives. */
67
+ data: Readonly<Record<string, JsonValue>>;
60
68
  /** The program's diagnostics; empty until one arrives. */
61
69
  diagnostics: ReadonlyArray<Diagnostic>;
62
70
  /** `{ code, message }` when `status` is "error". */
package/dist/client.js CHANGED
@@ -113,6 +113,7 @@ function pageKey(name, props) {
113
113
  }
114
114
  function toPageResult(result) {
115
115
  return {
116
+ data: result.data?.data ?? {},
116
117
  diagnostics: result.data?.diagnostics ?? [],
117
118
  error: result.status === "error" ? errorDataOf(result.error) : null,
118
119
  program: result.data?.program ?? null,
@@ -169,6 +170,7 @@ function createJigsClient(options) {
169
170
  }, { signal: context.signal });
170
171
  noteVersion(reply.version, pageKey(name, props));
171
172
  return {
173
+ data: reply.data,
172
174
  diagnostics: reply.diagnostics,
173
175
  program: reply.program
174
176
  };
@@ -94,7 +94,9 @@ export interface ViewController {
94
94
  /**
95
95
  * Replaces the provided data, by slot name. Every read of a slot whose
96
96
  * value changed, compared as JSON, gets the new value, as a refetched
97
- * query's does; a slot left out reads as `UNAVAILABLE`.
97
+ * query's does; a slot left out reads as `UNAVAILABLE`. A value that is
98
+ * the same object as before is not compared again, so a page that keeps
99
+ * its values' identity pays nothing for an unchanged slot.
98
100
  */
99
101
  setData: (values: Readonly<Record<string, JsonValue>> | undefined) => void;
100
102
  /** Replaces what each new issue is given to; `undefined` stops reporting. */
@@ -516,16 +516,27 @@ function createViewController(client) {
516
516
  },
517
517
  setData: (values) => {
518
518
  const next = /* @__PURE__ */ new Map();
519
+ const changed = /* @__PURE__ */ new Set();
519
520
  for (const [name, value] of Object.entries(values ?? {})) {
520
- const text = JSON.stringify(value);
521
521
  const before = provided.get(name);
522
- next.set(name, before?.text === text ? before : {
522
+ if (before !== void 0 && Object.is(before.value, value)) {
523
+ next.set(name, before);
524
+ continue;
525
+ }
526
+ const text = JSON.stringify(value);
527
+ if (before?.text === text) {
528
+ next.set(name, before);
529
+ continue;
530
+ }
531
+ next.set(name, {
523
532
  text,
524
533
  value
525
534
  });
535
+ changed.add(name);
526
536
  }
537
+ for (const name of provided.keys()) if (!next.has(name)) changed.add(name);
527
538
  provided = next;
528
- for (const [key, name] of slotReads) sendQuery(key, slotResult(name));
539
+ for (const [key, name] of slotReads) if (changed.has(name)) sendQuery(key, slotResult(name));
529
540
  },
530
541
  setIssueHandler: (handler) => {
531
542
  issueHandler = handler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jigs.design/client",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "createJigsClient: the browser's transport and query cache. No React.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@tanstack/query-core": "5.104.4",
29
- "@jigs.design/runtime": "0.3.1",
30
- "@jigs.design/protocol": "0.3.1"
29
+ "@jigs.design/protocol": "0.3.3",
30
+ "@jigs.design/runtime": "0.3.3"
31
31
  }
32
32
  }