@jxsuite/runtime 6.0.2 → 6.1.0

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/runtime.js CHANGED
@@ -3143,16 +3143,51 @@ var _templateErrorHandler = null;
3143
3143
  function setTemplateErrorHandler(handler) {
3144
3144
  _templateErrorHandler = handler;
3145
3145
  }
3146
+ function warnTemplateError(source, error) {
3147
+ if (!reportedTemplates.has(source)) {
3148
+ reportedTemplates.add(source);
3149
+ console.warn(`jx: template ${JSON.stringify(source)} threw:`, error);
3150
+ }
3151
+ }
3152
+ var pendingLookups = 0;
3153
+ var heldTemplateErrors = new Map;
3154
+ var lookupWaiters = [];
3155
+ function holdTemplateErrorsFor(lookup) {
3156
+ pendingLookups += 1;
3157
+ lookup.finally(() => {
3158
+ pendingLookups -= 1;
3159
+ if (pendingLookups === 0) {
3160
+ for (const { error, source } of heldTemplateErrors.values()) {
3161
+ warnTemplateError(source, error);
3162
+ }
3163
+ heldTemplateErrors.clear();
3164
+ for (const wake of lookupWaiters.splice(0)) {
3165
+ wake();
3166
+ }
3167
+ }
3168
+ });
3169
+ }
3170
+ function lookupsSettled() {
3171
+ if (pendingLookups === 0) {
3172
+ return Promise.resolve();
3173
+ }
3174
+ return new Promise((wake) => {
3175
+ lookupWaiters.push(wake);
3176
+ });
3177
+ }
3146
3178
  function bindTemplate(source, run, fallback) {
3147
3179
  effect(() => {
3148
3180
  try {
3149
3181
  run();
3182
+ heldTemplateErrors.delete(run);
3150
3183
  } catch (error) {
3184
+ const thrown = error instanceof Error ? error : new Error(String(error));
3151
3185
  if (_templateErrorHandler) {
3152
- _templateErrorHandler(error instanceof Error ? error : new Error(String(error)), source);
3153
- } else if (!reportedTemplates.has(source)) {
3154
- reportedTemplates.add(source);
3155
- console.warn(`jx: template ${JSON.stringify(source)} threw:`, error);
3186
+ _templateErrorHandler(thrown, source);
3187
+ } else if (pendingLookups > 0) {
3188
+ heldTemplateErrors.set(run, { error: thrown, source });
3189
+ } else {
3190
+ warnTemplateError(source, thrown);
3156
3191
  }
3157
3192
  fallback?.();
3158
3193
  }
@@ -3441,9 +3476,44 @@ function renderNode(def, state, options) {
3441
3476
  el.append(renderNode(child, localState, childOpts));
3442
3477
  }
3443
3478
  }
3479
+ } else if (isTemplateString(kids)) {
3480
+ renderComputedChildren(el, kids, localState, {
3481
+ ...options,
3482
+ _ns: childNs,
3483
+ _path: [...path, "children"]
3484
+ });
3444
3485
  }
3445
3486
  return el;
3446
3487
  }
3488
+ function renderComputedChildren(el, template, state, options) {
3489
+ const path = options._path ?? [];
3490
+ let live = null;
3491
+ const retire = () => {
3492
+ el.replaceChildren();
3493
+ live?.stop();
3494
+ live = null;
3495
+ };
3496
+ bindTemplate(template, () => {
3497
+ const nodes = evaluateValueTemplate(template, state);
3498
+ retire();
3499
+ if (!Array.isArray(nodes)) {
3500
+ return;
3501
+ }
3502
+ const scope = effectScope(true);
3503
+ live = scope;
3504
+ pauseTracking();
3505
+ try {
3506
+ scope.run(() => {
3507
+ for (const [i, child] of nodes.entries()) {
3508
+ el.append(renderNode(child, state, { ...options, _path: [...path, i] }));
3509
+ }
3510
+ });
3511
+ } finally {
3512
+ resetTracking();
3513
+ }
3514
+ }, retire);
3515
+ onScopeDispose(() => live?.stop(), true);
3516
+ }
3447
3517
  function applyProperties(el, def, state) {
3448
3518
  for (const [key, val] of Object.entries(def)) {
3449
3519
  if (RESERVED_KEYS.has(key)) {
@@ -4114,20 +4184,22 @@ async function resolvePrototype(def, state, key, base, ctx) {
4114
4184
  clearTimeout(debounceTimer);
4115
4185
  }
4116
4186
  });
4117
- const doFetch = () => fetch(url, {
4118
- method: def.method ?? "GET",
4119
- signal: controller.signal,
4120
- ...def.headers && { headers: def.headers },
4121
- ...def.body && {
4122
- body: isNonNullObject(def.body) ? JSON.stringify(def.body) : def.body
4123
- }
4124
- }).then((r) => r.ok ? r.json() : Promise.reject(r.statusText)).then((d) => {
4125
- s.value = d;
4126
- }).catch((error) => {
4127
- if (!(error instanceof Error && error.name === "AbortError")) {
4128
- s.value = { error: String(error) };
4129
- }
4130
- });
4187
+ const doFetch = () => {
4188
+ holdTemplateErrorsFor(fetch(url, {
4189
+ method: def.method ?? "GET",
4190
+ signal: controller.signal,
4191
+ ...def.headers && { headers: def.headers },
4192
+ ...def.body && {
4193
+ body: isNonNullObject(def.body) ? JSON.stringify(def.body) : def.body
4194
+ }
4195
+ }).then((r) => r.ok ? r.json() : Promise.reject(r.statusText)).then((d) => {
4196
+ s.value = d;
4197
+ }).catch((error) => {
4198
+ if (!(error instanceof Error && error.name === "AbortError")) {
4199
+ s.value = { error: String(error) };
4200
+ }
4201
+ }));
4202
+ };
4131
4203
  if (debounceMs > 0) {
4132
4204
  debounceTimer = setTimeout(doFetch, debounceMs);
4133
4205
  } else {
@@ -4454,20 +4526,21 @@ async function resolveViaDevProxy(def, state, key, base) {
4454
4526
  return r.json();
4455
4527
  });
4456
4528
  const s = ref(null);
4529
+ const resolveInto = (resolvedConfig) => {
4530
+ holdTemplateErrorsFor(doResolve(resolvedConfig).then((value) => {
4531
+ s.value = value;
4532
+ }).catch((error) => console.error("Jx dev proxy:", error)));
4533
+ };
4457
4534
  if (hasTemplates) {
4458
4535
  effect(() => {
4459
4536
  const resolvedConfig = {};
4460
4537
  for (const [k, v] of Object.entries(config)) {
4461
4538
  resolvedConfig[k] = isTemplateString(v) ? evaluateTemplate(v, state) : v;
4462
4539
  }
4463
- doResolve(resolvedConfig).then((value) => {
4464
- s.value = value;
4465
- }).catch((error) => console.error("Jx dev proxy:", error));
4540
+ resolveInto(resolvedConfig);
4466
4541
  });
4467
4542
  } else {
4468
- doResolve(config).then((value) => {
4469
- s.value = value;
4470
- }).catch((error) => console.error("Jx dev proxy:", error));
4543
+ resolveInto(config);
4471
4544
  }
4472
4545
  return s;
4473
4546
  }
@@ -4476,7 +4549,7 @@ function latestServerCall(s, invoke, label) {
4476
4549
  return (args) => {
4477
4550
  seq += 1;
4478
4551
  const n = seq;
4479
- new Promise((settle) => {
4552
+ holdTemplateErrorsFor(new Promise((settle) => {
4480
4553
  settle(invoke(args));
4481
4554
  }).then((result) => {
4482
4555
  if (n === seq) {
@@ -4486,7 +4559,7 @@ function latestServerCall(s, invoke, label) {
4486
4559
  if (n === seq) {
4487
4560
  console.error(label, error);
4488
4561
  }
4489
- });
4562
+ }));
4490
4563
  };
4491
4564
  }
4492
4565
  async function resolveServerFunction(def, state, key, base) {
@@ -5223,6 +5296,7 @@ export {
5223
5296
  isNestedSelectorKey,
5224
5297
  isSignal,
5225
5298
  isSingleExpression,
5299
+ lookupsSettled,
5226
5300
  mount,
5227
5301
  observeScope,
5228
5302
  preloadDocument,
@@ -5261,5 +5335,5 @@ export {
5261
5335
  transposeCanvasUnits
5262
5336
  };
5263
5337
 
5264
- //# debugId=938A15203F1CC52664756E2164756E21
5338
+ //# debugId=A334DCA3F0B40F7E64756E2164756E21
5265
5339
  //# sourceMappingURL=runtime.js.map