teamplay 0.4.0-alpha.86 → 0.4.0-alpha.87

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.
@@ -1007,9 +1007,10 @@ function diffDeepCompatSync ($signal, before, after) {
1007
1007
  }
1008
1008
 
1009
1009
  if (isDiffableObject(before, after)) {
1010
+ const preservePath = $signal[SEGMENTS]
1010
1011
  for (const key of Object.keys(before)) {
1011
1012
  if (Object.prototype.hasOwnProperty.call(after, key)) continue
1012
- delPrivateCompatSync(getChildSignal($signal, key))
1013
+ delPrivateCompatSync(getChildSignal($signal, key), { preservePath })
1013
1014
  }
1014
1015
  for (const key of Object.keys(after)) {
1015
1016
  diffDeepCompatSync(getChildSignal($signal, key), before[key], after[key])
@@ -1055,12 +1056,12 @@ function setReplacePrivateCompatSync ($signal, value) {
1055
1056
  mirrorRefMutationFromTarget(segments, value)
1056
1057
  }
1057
1058
 
1058
- function delPrivateCompatSync ($signal) {
1059
+ function delPrivateCompatSync ($signal, options) {
1059
1060
  const segments = $signal[SEGMENTS]
1060
1061
  if (segments.length === 0) throw Error('Can\'t delete the root signal data')
1061
1062
  const idFields = getIdFieldsForSegments(segments)
1062
1063
  if (isIdFieldPath(segments, idFields)) return
1063
- delPrivateData(getOwningRootId($signal), segments)
1064
+ delPrivateData(getOwningRootId($signal), segments, options)
1064
1065
  }
1065
1066
 
1066
1067
  function deepEqualCompat (left, right) {
package/orm/Doc.js CHANGED
@@ -284,6 +284,12 @@ export class DocSubscriptions {
284
284
  return count
285
285
  }
286
286
 
287
+ getEntryTrackedTotal (entry) {
288
+ if (!entry) return undefined
289
+ const total = this.getEntryTotalCount(entry)
290
+ if (total > 0 || entry.pendingDestroy) return total
291
+ }
292
+
287
293
  syncOwnerMirror () {}
288
294
 
289
295
  clearOwnerMirror () {}
@@ -293,14 +299,18 @@ export class DocSubscriptions {
293
299
  deleteEntryIfEmpty (hash) {
294
300
  const entry = this.entries.get(hash)
295
301
  if (!entry) return
296
- if (entry.owners.size > 0) return
297
- if (entry.retainCount > 0) return
298
- if (entry.pendingDestroy) return
299
- if (entry.runtime) return
300
- if (entry.phase === 'transition') return
302
+ if (!this.canDeleteEntry(entry)) return
301
303
  this.entries.delete(hash)
302
304
  }
303
305
 
306
+ canDeleteEntry (entry) {
307
+ if (!entry) return false
308
+ if (this.getEntryTrackedTotal(entry) !== undefined) return false
309
+ if (entry.runtime) return false
310
+ if (entry.phase === 'transition') return false
311
+ return true
312
+ }
313
+
304
314
  ensureRuntime (hash, segments) {
305
315
  const entry = this.getOrCreateEntry(hash, segments)
306
316
  if (!entry.runtime) {
@@ -775,18 +785,11 @@ export class DocSubscriptions {
775
785
 
776
786
  getTrackedCount (hash) {
777
787
  const entry = this.entries.get(hash)
778
- if (entry) {
779
- const total = this.getEntryTotalCount(entry)
780
- if (total > 0 || entry.pendingDestroy) return total
781
- }
782
- return undefined
788
+ return this.getEntryTrackedTotal(entry)
783
789
  }
784
790
 
785
791
  getTrackedHashCountSize () {
786
- return countMapLike(this.entries, entry => {
787
- const total = this.getEntryTotalCount(entry)
788
- return total > 0 || !!entry.pendingDestroy
789
- })
792
+ return countMapLike(this.entries, entry => this.getEntryTrackedTotal(entry) !== undefined)
790
793
  }
791
794
 
792
795
  getOwnerMeta (ownerKey) {
@@ -50,13 +50,13 @@ export function setReplacePrivateData (rootId, logicalSegments, value) {
50
50
  _setReplace(segments, value, context.getPrivateDataRoot(), getModelEventContext(rootId, logicalSegments))
51
51
  }
52
52
 
53
- export function delPrivateData (rootId, logicalSegments) {
53
+ export function delPrivateData (rootId, logicalSegments, options = {}) {
54
54
  if (!isPrivateCollectionSegments(logicalSegments)) return
55
55
  const context = getRootContext(rootId, false)
56
56
  if (!context) return
57
57
  const segments = getPrivateDataSegments(logicalSegments)
58
58
  _del(segments, context.getPrivateDataRoot(), getModelEventContext(rootId, logicalSegments))
59
- pruneEmptyPrivateParents(context.getPrivateDataRoot(), context.getPrivateDataRawRoot(), segments)
59
+ pruneEmptyPrivateParents(context.getPrivateDataRoot(), context.getPrivateDataRawRoot(), segments, options)
60
60
  }
61
61
 
62
62
  export function arrayPushPrivateData (rootId, logicalSegments, value) {
@@ -132,8 +132,11 @@ function cloneValue (value) {
132
132
  return value
133
133
  }
134
134
 
135
- function pruneEmptyPrivateParents (tree, treeRaw, segments) {
135
+ function pruneEmptyPrivateParents (tree, treeRaw, segments, options = {}) {
136
136
  if (!Array.isArray(segments) || segments.length < 2) return
137
+ const preservePath = Array.isArray(options.preservePath)
138
+ ? getPrivateDataSegments(options.preservePath)
139
+ : null
137
140
  const parents = []
138
141
  let node = tree
139
142
  let nodeRaw = treeRaw
@@ -145,6 +148,8 @@ function pruneEmptyPrivateParents (tree, treeRaw, segments) {
145
148
  }
146
149
  for (let i = parents.length - 1; i >= 0; i--) {
147
150
  const [parent, parentRaw, segment] = parents[i]
151
+ const currentPath = segments.slice(0, i + 1)
152
+ if (segmentsEqual(currentPath, preservePath)) break
148
153
  const valueRaw = parentRaw?.[segment]
149
154
  if (!isPlainObjectEmpty(valueRaw)) break
150
155
  delete parent[segment]
@@ -154,3 +159,12 @@ function pruneEmptyPrivateParents (tree, treeRaw, segments) {
154
159
  function isPlainObjectEmpty (value) {
155
160
  return value != null && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0
156
161
  }
162
+
163
+ function segmentsEqual (left, right) {
164
+ if (!Array.isArray(left) || !Array.isArray(right)) return false
165
+ if (left.length !== right.length) return false
166
+ for (let i = 0; i < left.length; i++) {
167
+ if (left[i] !== right[i]) return false
168
+ }
169
+ return true
170
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamplay",
3
- "version": "0.4.0-alpha.86",
3
+ "version": "0.4.0-alpha.87",
4
4
  "description": "Full-stack signals ORM with multiplayer",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -83,5 +83,5 @@
83
83
  ]
84
84
  },
85
85
  "license": "MIT",
86
- "gitHead": "1a97cd53facf3d591549158e306f6167ccf086e0"
86
+ "gitHead": "dd7b2ff38d9b84e0b2eb24217e41f3ee3644592f"
87
87
  }