teamplay 0.4.0-alpha.31 → 0.4.0-alpha.32

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.
@@ -116,6 +116,8 @@ $.users.user1.scope('users', 'user2')
116
116
  Creates a lightweight alias between signals (minimal Racer-style ref).
117
117
  Mutations on the alias are forwarded to the target. The alias mirrors target updates.
118
118
  Reads (`get`/`peek`) are forwarded to the target while the ref is active.
119
+ Ref mirroring is scheduled through Teamplay runtime scheduler, so updates remain batch-friendly
120
+ and do not leak intermediate ref states during a single batched cycle.
119
121
 
120
122
  ```js
121
123
  const $local = $.local.value
@@ -40,7 +40,7 @@ import { on as onCustomEvent, removeListener as removeCustomEventListener } from
40
40
  import { normalizePattern, onModelEvent, removeModelListener } from './modelEvents.js'
41
41
  import { setRefLink, removeRefLink } from './refRegistry.js'
42
42
  import { REF_TARGET, resolveRefSignalSafe } from './refFallback.js'
43
- import { runInBatch } from '../batchScheduler.js'
43
+ import { runInBatch, scheduleReaction } from '../batchScheduler.js'
44
44
 
45
45
  class SignalCompat extends Signal {
46
46
  static ID_FIELDS = ['_id', 'id']
@@ -577,6 +577,7 @@ class SignalCompat extends Signal {
577
577
  }
578
578
 
579
579
  const REFS = Symbol('compat refs')
580
+ const SKIP_REF_TICK = Symbol('compat ref skip tick')
580
581
 
581
582
  function getRefStore ($signal) {
582
583
  const $root = getRoot($signal) || $signal
@@ -586,15 +587,25 @@ function getRefStore ($signal) {
586
587
 
587
588
  function createRefLink ($from, $to) {
588
589
  const toReaction = observe(() => {
589
- const value = $to.get()
590
+ const value = readRefValue($to)
591
+ if (value === SKIP_REF_TICK) return
590
592
  trackDeep(value)
591
593
  setDiffDeepBypassRef($from, deepCopy(value))
592
- })
594
+ }, { scheduler: scheduleReaction })
593
595
  return () => {
594
596
  unobserve(toReaction)
595
597
  }
596
598
  }
597
599
 
600
+ function readRefValue ($signal) {
601
+ try {
602
+ return $signal.get()
603
+ } catch (err) {
604
+ if (isThenable(err)) return SKIP_REF_TICK
605
+ throw err
606
+ }
607
+ }
608
+
598
609
  function trackDeep (value, seen = new Set()) {
599
610
  if (!value || typeof value !== 'object') return
600
611
  if (seen.has(value)) return
@@ -632,6 +643,10 @@ function isReactLike (value) {
632
643
  return !!(value && typeof value === 'object' && typeof value.$$typeof === 'symbol')
633
644
  }
634
645
 
646
+ function isThenable (value) {
647
+ return !!value && typeof value.then === 'function'
648
+ }
649
+
635
650
  function resolveRefTarget ($signal, target, methodName) {
636
651
  if (isSignalLike(target)) return target
637
652
  if (typeof target === 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamplay",
3
- "version": "0.4.0-alpha.31",
3
+ "version": "0.4.0-alpha.32",
4
4
  "description": "Full-stack signals ORM with multiplayer",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -81,5 +81,5 @@
81
81
  ]
82
82
  },
83
83
  "license": "MIT",
84
- "gitHead": "a0efde2a05bc7e45d497e5b76eb7bd2efe22d12c"
84
+ "gitHead": "384c14383a45af21bad2f752011db1462f7d8628"
85
85
  }