braid-text 0.3.17 → 0.3.19

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.
@@ -118,7 +118,7 @@ function simpleton_client(url, {
118
118
  var outstanding_changes = 0 // PUTs sent, not yet ACKed
119
119
  var max_outstanding_changes = 10 // throttle limit
120
120
  var throttled = false
121
- var throttled_update = null
121
+ var throttled_updates = []
122
122
  var ac = new AbortController()
123
123
 
124
124
  // ── Subscription (GET) ──────────────────────────────────────────────
@@ -150,8 +150,11 @@ function simpleton_client(url, {
150
150
  // parents match our client_version exactly. This ensures
151
151
  // we stay on a single line of time.
152
152
  update.parents.sort()
153
- if (versions_eq(client_version, update.parents))
154
- if (throttled) throttled_update = update
153
+ var last_queued = throttled_updates.length
154
+ ? throttled_updates[throttled_updates.length - 1].version
155
+ : client_version
156
+ if (versions_eq(last_queued, update.parents))
157
+ if (throttled) throttled_updates.push(update)
155
158
  else await apply_update(update)
156
159
  }, on_error)
157
160
  }).catch(on_error)
@@ -265,10 +268,10 @@ function simpleton_client(url, {
265
268
  if (!change) {
266
269
  if (throttled) {
267
270
  throttled = false
268
- if (throttled_update &&
269
- versions_eq(client_version, throttled_update.parents))
270
- apply_update(throttled_update).catch(on_error)
271
- throttled_update = null
271
+ for (var update of throttled_updates)
272
+ if (versions_eq(client_version, update.parents))
273
+ apply_update(update).catch(on_error)
274
+ throttled_updates = []
272
275
  }
273
276
  return
274
277
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.3.17",
3
+ "version": "0.3.19",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-text",
package/server.js CHANGED
@@ -718,7 +718,6 @@ function create_braid_text() {
718
718
  }
719
719
  }
720
720
 
721
- options.my_last_sent_version = x.version
722
721
  resource.simpleton_clients.add(options)
723
722
  options.signal?.addEventListener('abort', () =>
724
723
  resource.simpleton_clients.delete(options))
@@ -1015,7 +1014,6 @@ function create_braid_text() {
1015
1014
 
1016
1015
  if (braid_text.verbose) console.log(`sending from rebase: ${JSON.stringify(x)}`)
1017
1016
  client.my_subscribe(x)
1018
- client.my_last_sent_version = x.version
1019
1017
 
1020
1018
  delete client.my_timeout
1021
1019
  }, time_override ?? Math.min(3000, 23 * Math.pow(1.5, client.my_unused_version_count - 1)))
@@ -1033,7 +1031,10 @@ function create_braid_text() {
1033
1031
 
1034
1032
  let x = { version: resource.version }
1035
1033
  if (peer && client.peer === peer) {
1036
- if (!v_eq(client.my_last_sent_version, parents)) {
1034
+ if (!v_eq(resource.version, [version])) {
1035
+ // the resource has other changes beyond this
1036
+ // PUT, so the client is behind — start a
1037
+ // timeout to batch and rebase
1037
1038
  client.my_unused_version_count = (client.my_unused_version_count ?? 0) + 1
1038
1039
  set_timeout()
1039
1040
  continue
@@ -1041,37 +1042,16 @@ function create_braid_text() {
1041
1042
  delete client.my_unused_version_count
1042
1043
  }
1043
1044
 
1044
- x.parents = [version]
1045
- if (!v_eq(x.version, x.parents)) {
1046
- // Note: this rebase will never trigger in the
1047
- // presence of the timeout logic above, because
1048
- // any version that would cause x.version to
1049
- // differ from x.parents would have already
1050
- // updated my_last_sent_version when forwarding
1051
- // other peers' changes to this client, causing
1052
- // a mismatch and triggering a timeout instead.
1053
- //
1054
- // However, this is the standard rebase path and
1055
- // is left here for implementations that omit the
1056
- // timeout optimization — without it, this branch
1057
- // is needed to rebase the client's version when
1058
- // concurrent edits have been merged.
1059
- if (braid_text.verbose) console.log("rebasing..")
1060
- x.patches = get_xf_patches(resource.doc, OpLog_remote_to_local(resource.doc, x.parents))
1061
- } else {
1062
- // this client already has this version,
1063
- // so let's pretend to send it back, but not
1064
- if (braid_text.verbose) console.log(`not reflecting back to simpleton`)
1065
- client.my_last_sent_version = x.version
1066
- continue
1067
- }
1045
+ // this client already has this version,
1046
+ // so let's pretend to send it back, but not
1047
+ if (braid_text.verbose) console.log(`not reflecting back to simpleton`)
1048
+ continue
1068
1049
  } else {
1069
1050
  x.parents = version_before
1070
1051
  x.patches = patches
1071
1052
  }
1072
1053
  if (braid_text.verbose) console.log(`sending: ${JSON.stringify(x)}`)
1073
1054
  post_commit_updates.push([client, x])
1074
- client.my_last_sent_version = x.version
1075
1055
  }
1076
1056
  } else {
1077
1057
  if (resource.simpleton_clients.size) {
@@ -1084,7 +1064,6 @@ function create_braid_text() {
1084
1064
  for (let client of resource.simpleton_clients) {
1085
1065
  if (client.my_timeout) continue
1086
1066
  post_commit_updates.push([client, x])
1087
- client.my_last_sent_version = x.version
1088
1067
  }
1089
1068
  }
1090
1069
  }