braid-text 0.2.79 → 0.2.80

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/index.js CHANGED
@@ -197,6 +197,7 @@ function create_braid_text() {
197
197
  disconnect()
198
198
  connect()
199
199
  }
200
+ options.on_res?.(remote_result)
200
201
  // on_error will call handle_error when connection drops
201
202
  } catch (e) {
202
203
  handle_error(e)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.2.79",
3
+ "version": "0.2.80",
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/test/tests.js CHANGED
@@ -1981,6 +1981,47 @@ runTest(
1981
1981
  'created locally'
1982
1982
  )
1983
1983
 
1984
+ runTest(
1985
+ "test braid_text.sync on_res callback",
1986
+ async () => {
1987
+ var local_key = 'test-local-' + Math.random().toString(36).slice(2)
1988
+ var remote_key = 'test-remote-' + Math.random().toString(36).slice(2)
1989
+
1990
+ // Create the remote resource first
1991
+ var r = await braid_fetch(`/${remote_key}`, {
1992
+ method: 'PUT',
1993
+ body: 'remote content'
1994
+ })
1995
+ if (!r.ok) return 'put failed: ' + r.status
1996
+
1997
+ // Start sync with on_res callback and verify it gets called
1998
+ var r = await braid_fetch(`/eval`, {
1999
+ method: 'PUT',
2000
+ body: `void (async () => {
2001
+ var ac = new AbortController()
2002
+ var got_res = false
2003
+
2004
+ braid_text.sync('/${local_key}', new URL('http://localhost:8889/${remote_key}'), {
2005
+ signal: ac.signal,
2006
+ on_res: (response) => {
2007
+ got_res = response && typeof response.headers !== 'undefined'
2008
+ }
2009
+ })
2010
+
2011
+ // Wait for sync to establish and on_res to be called
2012
+ await new Promise(done => setTimeout(done, 200))
2013
+
2014
+ ac.abort()
2015
+ res.end(got_res ? 'on_res called' : 'on_res not called')
2016
+ })()`
2017
+ })
2018
+ if (!r.ok) return 'eval failed: ' + r.status
2019
+
2020
+ return await r.text()
2021
+ },
2022
+ 'on_res called'
2023
+ )
2024
+
1984
2025
  runTest(
1985
2026
  "test getting a binary update from a subscription",
1986
2027
  async () => {