teamplay 0.3.15 → 0.3.17

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/orm/Doc.js CHANGED
@@ -162,24 +162,22 @@ class DocSubscriptions {
162
162
  constructor () {
163
163
  this.subCount = new Map()
164
164
  this.docs = new Map()
165
- this.initialized = new Map()
166
165
  this.fr = new FinalizationRegistry(segments => this.destroy(segments))
167
166
  }
168
167
 
169
168
  init ($doc) {
170
169
  const segments = [...$doc[SEGMENTS]]
171
170
  const hash = hashDoc(segments)
172
- if (this.initialized.has(hash)) return
173
- this.initialized.set(hash, true)
174
-
175
- this.fr.register($doc, segments, $doc)
176
-
177
171
  let doc = this.docs.get(hash)
178
- if (!doc) {
172
+ if (doc) {
173
+ if (doc.initialized) return
174
+ doc.init()
175
+ } else {
179
176
  doc = new Doc(...segments)
180
177
  this.docs.set(hash, doc)
178
+ this.fr.register($doc, segments, $doc)
179
+ doc.init()
181
180
  }
182
- doc.init()
183
181
  }
184
182
 
185
183
  subscribe ($doc) {
@@ -216,11 +214,10 @@ class DocSubscriptions {
216
214
  const hash = hashDoc(segments)
217
215
  const doc = this.docs.get(hash)
218
216
  if (!doc) return
219
- this.subCount.delete(hash)
220
- this.initialized.delete(hash)
221
- // If the document was initialized as part of query and wasn't directly subscribed to, we should not unsubscribe from it.
217
+ // Wait until after unsubscribe to delete subCount and docs
222
218
  if (doc.subscribed) await doc.unsubscribe()
223
- if (doc.subscribed) return // if we subscribed again while waiting for unsubscribe, we don't delete the doc
219
+ if (doc.subscribed) return // Subscribed again while unsubscribing
220
+ this.subCount.delete(hash)
224
221
  this.docs.delete(hash)
225
222
  }
226
223
  }
package/orm/Signal.js CHANGED
@@ -24,7 +24,7 @@ export const SEGMENTS = Symbol('path segments targeting the particular node in t
24
24
  export const ARRAY_METHOD = Symbol('run array method on the signal')
25
25
  export const GET = Symbol('get the value of the signal - either observed or raw')
26
26
  export const GETTERS = Symbol('get the list of this signal\'s getters')
27
- const DEFAULT_GETTERS = ['path', 'id', 'get', 'peek', 'getId', 'map', 'reduce', 'find', 'getIds']
27
+ const DEFAULT_GETTERS = ['path', 'id', 'get', 'peek', 'getId', 'map', 'reduce', 'find', 'getIds', 'getCollection']
28
28
 
29
29
  export default class Signal extends Function {
30
30
  static [GETTERS] = DEFAULT_GETTERS
@@ -108,6 +108,14 @@ export default class Signal extends Function {
108
108
  return this[SEGMENTS][this[SEGMENTS].length - 1]
109
109
  }
110
110
 
111
+ getCollection () {
112
+ if (this[SEGMENTS].length === 0) throw Error('Can\'t get the id of the root signal')
113
+ if (this[SEGMENTS][0] === AGGREGATIONS) {
114
+ return getAggregationCollectionName(this[SEGMENTS])
115
+ }
116
+ return this[SEGMENTS][0]
117
+ }
118
+
111
119
  * [Symbol.iterator] () {
112
120
  if (this[IS_QUERY]) {
113
121
  const ids = _get([QUERIES, this[HASH], 'ids'])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamplay",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "description": "Full-stack signals ORM with multiplayer",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -23,12 +23,12 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@nx-js/observer-util": "^4.1.3",
26
- "@teamplay/backend": "^0.3.15",
27
- "@teamplay/cache": "^0.3.15",
28
- "@teamplay/channel": "^0.3.15",
29
- "@teamplay/debug": "^0.3.15",
30
- "@teamplay/schema": "^0.3.15",
31
- "@teamplay/utils": "^0.3.15",
26
+ "@teamplay/backend": "^0.3.17",
27
+ "@teamplay/cache": "^0.3.17",
28
+ "@teamplay/channel": "^0.3.17",
29
+ "@teamplay/debug": "^0.3.17",
30
+ "@teamplay/schema": "^0.3.17",
31
+ "@teamplay/utils": "^0.3.17",
32
32
  "diff-match-patch": "^1.0.5",
33
33
  "events": "^3.3.0",
34
34
  "json0-ot-diff": "^1.1.2",
@@ -63,5 +63,5 @@
63
63
  ]
64
64
  },
65
65
  "license": "MIT",
66
- "gitHead": "108543261b228e76cfd4ceb4673b8190bb31bbb8"
66
+ "gitHead": "3c86c80a5a9af166a60428c608cc73dcdf281769"
67
67
  }
@@ -1,6 +1,4 @@
1
- export const REGISTRY_SWEEP_INTERVAL = 10_000
2
- export const MOCK_FINALIZATION_TIMEOUT = 10_000
3
- const PERMANENT = false
1
+ export const REGISTRY_SWEEP_INTERVAL = 10000
4
2
 
5
3
  // This is a mock implementation of FinalizationRegistry which doesn't actually
6
4
  // finalize anything. It's used in environments where FinalizationRegistry is not
@@ -42,7 +40,7 @@ export class WeakRefBasedFinalizationRegistry {
42
40
  register (target, value, token) {
43
41
  this.registrations.set(this.counter, {
44
42
  targetRef: new WeakRef(target),
45
- tokenRef: token && new WeakRef(token),
43
+ tokenRef: token != null ? new WeakRef(token) : undefined,
46
44
  value
47
45
  })
48
46
  this.counter++
@@ -50,9 +48,11 @@ export class WeakRefBasedFinalizationRegistry {
50
48
  }
51
49
 
52
50
  unregister (token) {
51
+ if (token == null) return
53
52
  this.registrations.forEach((registration, key) => {
54
- if (registration?.tokenRef.deref() !== token) return
55
- this.registrations.delete(key)
53
+ if (registration.tokenRef?.deref() === token) {
54
+ this.registrations.delete(key)
55
+ }
56
56
  })
57
57
  }
58
58
 
@@ -65,7 +65,7 @@ export class WeakRefBasedFinalizationRegistry {
65
65
  if (registration.targetRef.deref() !== undefined) return
66
66
  const value = registration.value
67
67
  this.registrations.delete(key)
68
- setTimeout(() => this.finalize(value), MOCK_FINALIZATION_TIMEOUT)
68
+ this.finalize(value)
69
69
  })
70
70
 
71
71
  if (this.registrations.size > 0) this.scheduleSweep()
@@ -81,12 +81,12 @@ let ExportedFinalizationRegistry
81
81
 
82
82
  if (typeof FinalizationRegistry !== 'undefined') {
83
83
  ExportedFinalizationRegistry = FinalizationRegistry
84
- } else if (typeof WeakRef !== 'undefined' && !PERMANENT) {
84
+ } else if (typeof WeakRef !== 'undefined') {
85
85
  console.warn('FinalizationRegistry is not available in this environment. ' +
86
86
  'Using a mock implementation: WeakRefBasedFinalizationRegistry')
87
87
  ExportedFinalizationRegistry = WeakRefBasedFinalizationRegistry
88
88
  } else {
89
- console.warn('FinalizationRegistry is not available in this environment. ' +
89
+ console.warn('Neither FinalizationRegistry nor WeakRef are available in this environment. ' +
90
90
  'Using a mock implementation: PermanentFinalizationRegistry')
91
91
  ExportedFinalizationRegistry = PermanentFinalizationRegistry
92
92
  }