@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.
- package/agents/generic.js +7 -13
- 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
|
-
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
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
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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) {
|