@knowlearning/agents 0.4.6 → 0.4.7

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.
Files changed (2) hide show
  1. package/agents/generic.js +7 -13
  2. package/package.json +1 -1
package/agents/generic.js CHANGED
@@ -14,10 +14,6 @@ function sanitizeJSONPatchPathSegment(s) {
14
14
  else return s
15
15
  }
16
16
 
17
- function copy(value) {
18
- return JSON.parse(JSON.stringify(value))
19
- }
20
-
21
17
  export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fetch, applyPatch, login, logout, reboot }) {
22
18
  let ws
23
19
  let user
@@ -40,11 +36,10 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
40
36
  let lastSentSI = -1
41
37
  let lastHeartbeat
42
38
 
43
- // TODO: probably an use "mutate" function from below
44
- const subscriptions = new MutableProxy({}, patch => queueMessage({scope: 'subscriptions', patch}))
45
- const uploads = new MutableProxy({}, patch => queueMessage({scope: 'uploads', patch}))
46
- const downloads = new MutableProxy({}, patch => queueMessage({scope: 'downloads', patch}))
47
- const patches = new MutableProxy({}, patch => queueMessage({scope: 'patches', patch}))
39
+ const subscriptions = mutate('subscriptions', false)
40
+ const uploads = mutate('uploads', false)
41
+ const downloads = mutate('downloads', false)
42
+ const patches = mutate('patches', false)
48
43
 
49
44
  log('INITIALIZING AGENT CONNECTION')
50
45
  initWS()
@@ -348,10 +343,9 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
348
343
  return interact('claims', [{ op: 'add', path: [domain], value: null }])
349
344
  }
350
345
 
351
- async function mutate(scope, initialize=true) {
352
- // TODO: probably can remove redundant copy
353
- const initial = initialize ? copy(await state(scope) || {}) : {}
354
- return new MutableProxy(initial, patch => interact(scope, patch))
346
+ function mutate(scope, initialize=true) {
347
+ const mp = s => new MutableProxy(s || {}, patch => interact(scope, patch))
348
+ return initialize ? state.then(mp) : mp({})
355
349
  }
356
350
 
357
351
  function reset(scope) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",