primitive-app 3.2.0-alpha.11 → 3.2.0-alpha.13

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/index.js CHANGED
@@ -9343,101 +9343,118 @@ function nf(e) {
9343
9343
  }
9344
9344
  }
9345
9345
  function rf(e) {
9346
- let { subscribeTo: t, queryParams: n, documentReady: r, loadData: a, pauseUpdates: o, reloadOnDocumentEvents: s = !0, debounceMs: c = 50, onError: l } = e, u = B(null), d = B(!1), f = B(!1), p = m(() => tf(r, !1)), h = m(() => tf(o, !1)), g = m(() => W(n) ?? null), _ = m(() => {
9347
- let e = g.value;
9346
+ let { subscribeTo: t, queryParams: n, documentReady: r, loadData: a, pauseUpdates: o, reloadOnDocumentEvents: s = !0, debounceMs: c = 50, onError: l } = e, u = B(null), d = B(!1), f = 0, p = null, h = () => {
9347
+ p === null && (p = ++f);
9348
+ }, g = m(() => tf(r, !1)), _ = m(() => tf(o, !1)), v = m(() => W(n) ?? null), y = m(() => {
9349
+ let e = v.value;
9348
9350
  return e === null ? null : nf(e);
9349
- }), v = async (e) => {
9350
- if (!p.value) {
9351
+ }), b = async (e) => {
9352
+ if (!g.value) {
9351
9353
  ef.debug("loadData skipped: not ready", {
9352
9354
  reason: e,
9353
- queryParams: se(g.value)
9355
+ queryParams: se(v.value)
9354
9356
  });
9355
9357
  return;
9356
9358
  }
9357
- if (h.value) {
9359
+ if (_.value) {
9358
9360
  ef.debug("loadData skipped: paused", {
9359
9361
  reason: e,
9360
- queryParams: se(g.value)
9362
+ queryParams: se(v.value)
9361
9363
  });
9362
9364
  return;
9363
9365
  }
9364
9366
  ef.debug("loadData start", {
9365
9367
  reason: e,
9366
- queryParams: se(g.value)
9368
+ queryParams: se(v.value)
9367
9369
  });
9370
+ let t = p ?? ++f;
9371
+ p = null;
9368
9372
  try {
9369
- let t = await a(g.value);
9370
- u.value = t, d.value || (d.value = !0, f.value = !0), ef.debug("loadData success", {
9373
+ let n = await a(v.value);
9374
+ if (t !== f) {
9375
+ ef.debug("loadData result dropped: a newer load started", { reason: e });
9376
+ return;
9377
+ }
9378
+ u.value = n, d.value = !0, ef.debug("loadData success", {
9371
9379
  reason: e,
9372
- queryParams: se(g.value),
9373
- data: t
9380
+ queryParams: se(v.value),
9381
+ data: n
9374
9382
  });
9375
- } catch (t) {
9383
+ } catch (n) {
9384
+ if (t !== f) {
9385
+ ef.debug("loadData error dropped: a newer load started", {
9386
+ reason: e,
9387
+ error: n
9388
+ });
9389
+ return;
9390
+ }
9376
9391
  if (l) try {
9377
- l(t);
9392
+ l(n);
9378
9393
  } catch (e) {
9379
9394
  ef.warn("onError handler threw", { handlerError: e });
9380
9395
  }
9381
9396
  ef.error("loadData error", {
9382
9397
  reason: e,
9383
- queryParams: se(g.value),
9384
- error: t
9398
+ queryParams: se(v.value),
9399
+ error: n
9385
9400
  });
9386
9401
  }
9387
- }, y = (0, $d.default)((e) => {
9388
- ef.debug("Reload scheduled", { reason: e }), v(e);
9389
- }, c), b = () => {
9390
- y("Manual");
9391
- }, x = [];
9402
+ }, x = (0, $d.default)((e) => {
9403
+ ef.debug("Reload scheduled", { reason: e }), b(e);
9404
+ }, c), S = (e) => {
9405
+ h(), x(e);
9406
+ }, C = () => {
9407
+ S("Manual");
9408
+ }, w = [];
9392
9409
  return I(async () => {
9393
9410
  for (let e of t) try {
9394
9411
  let t = e.subscribe(() => {
9395
- f.value && p.value && (h.value || y("Subscribed models changed"));
9412
+ g.value && (_.value || S("Subscribed models changed"));
9396
9413
  });
9397
- x.push(t);
9414
+ w.push(t);
9398
9415
  } catch (e) {
9399
9416
  ef.warn("Failed to subscribe to model", { error: e });
9400
9417
  }
9401
9418
  if (tf(s, !0)) try {
9402
9419
  let e = await i.getClientAsync(), t = () => {
9403
- f.value && p.value && (h.value || y("Document loaded"));
9420
+ g.value && (_.value || S("Document loaded"));
9404
9421
  }, n = () => {
9405
- f.value && p.value && (h.value || y("Document closed"));
9422
+ g.value && (_.value || S("Document closed"));
9406
9423
  };
9407
- e.on("documentLoaded", t), e.on("documentClosed", n), x.push(() => {
9424
+ e.on("documentLoaded", t), e.on("documentClosed", n), w.push(() => {
9408
9425
  e.off("documentLoaded", t), e.off("documentClosed", n);
9409
9426
  }), ef.debug("Subscribed to js-bao document events");
9410
9427
  } catch (e) {
9411
9428
  ef.warn("Failed to subscribe to js-bao client events", { error: e });
9412
9429
  }
9413
9430
  }), re(() => {
9414
- for (let e of x) try {
9431
+ for (let e of w) try {
9415
9432
  e();
9416
9433
  } catch {}
9417
- }), G(p, (e) => {
9434
+ }), G(g, (e) => {
9418
9435
  if (!e) {
9419
- ef.debug("documentReady became false; resetting state"), d.value = !1, f.value = !1;
9436
+ ef.debug("documentReady became false; resetting state"), d.value = !1;
9420
9437
  return;
9421
9438
  }
9422
- h.value ? ef.debug("documentReady became true but updates are paused; not scheduling load") : (ef.debug("documentReady became true; scheduling initial load"), y("Document became ready"));
9423
- }, { immediate: !0 }), G(_, (e) => {
9439
+ _.value ? ef.debug("documentReady became true but updates are paused; not scheduling load") : (ef.debug("documentReady became true; scheduling initial load"), S("Document became ready"));
9440
+ }, { immediate: !0 }), G(y, (e) => {
9424
9441
  if (e === null) {
9425
9442
  ef.debug("queryParams disabled (null)");
9426
9443
  return;
9427
9444
  }
9428
- if (!p.value) {
9445
+ if (!g.value) {
9429
9446
  ef.debug("queryParams changed but document not ready; ignoring", { signature: e });
9430
9447
  return;
9431
9448
  }
9432
- if (h.value) {
9449
+ if (_.value) {
9433
9450
  ef.debug("queryParams changed but updates are paused; ignoring", { signature: e });
9434
9451
  return;
9435
9452
  }
9436
- ef.debug("queryParams changed; scheduling reload", { signature: e }), y("Queries changed");
9453
+ ef.debug("queryParams changed; scheduling reload", { signature: e }), S("Queries changed");
9437
9454
  }), {
9438
9455
  data: u,
9439
9456
  initialDataLoaded: d,
9440
- reload: b
9457
+ reload: C
9441
9458
  };
9442
9459
  }
9443
9460
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primitive-app",
3
- "version": "3.2.0-alpha.11",
3
+ "version": "3.2.0-alpha.13",
4
4
  "license": "UNLICENSED",
5
5
  "author": "Primitive LLC",
6
6
  "type": "module",