@knowlearning/agents 0.2.4 → 0.2.6

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.
@@ -66,6 +66,7 @@ export default function EmbeddedAgent() {
66
66
  promise.watch = fn => {
67
67
  key
68
68
  .then( async k => {
69
+ if (watchFn) throw new Error('Only one watcher allowed')
69
70
  if (!watchers[k]) watchers[k] = []
70
71
  watchers[k].push(fn)
71
72
  watchFn = fn
package/agents/generic.js CHANGED
@@ -12,6 +12,10 @@ function sanitizeJSONPatchPathSegment(s) {
12
12
  else return s
13
13
  }
14
14
 
15
+ function copy(value) {
16
+ return JSON.parse(JSON.stringify(value))
17
+ }
18
+
15
19
  export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fetch, applyPatch, login, logout, reboot }) {
16
20
  let ws
17
21
  let user
@@ -192,7 +196,8 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
192
196
  promise.watch = fn => {
193
197
  key
194
198
  .then( k => {
195
- if (watchFn) throw new Error('Only one watcher allowed') // TODO: consider allowing more watchers per state call
199
+ if (watchFn) throw new Error('Only one watcher allowed')
200
+ if (!watchers[k]) watchers[k] = []
196
201
  watchers[k].push(fn)
197
202
  watchFn = fn
198
203
  })
@@ -283,7 +288,7 @@ export default function Agent({ host, token, WebSocket, protocol='ws', uuid, fet
283
288
  }
284
289
 
285
290
  async function mutate(scope, initialize=true) {
286
- const initial = initialize ? await state(scope) || {} : {}
291
+ const initial = initialize ? copy(await state(scope) || {}) : {}
287
292
  return new MutableProxy(initial, patch => interact(scope, patch))
288
293
  }
289
294
 
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
- "main": "package/node.js",
6
- "browser": "package/browser.js",
5
+ "main": "node.js",
6
+ "browser": "browser.js",
7
7
  "type": "module",
8
8
  "directories": {
9
9
  "example": "examples",
File without changes
File without changes
File without changes