@knowlearning/agents 0.5.3 → 0.5.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",
@@ -7,7 +7,7 @@ const copy = x => JSON.parse(JSON.stringify(x))
7
7
  export default async function (storeDefinition) {
8
8
  // Set up persistance
9
9
  const { scope } = await Agent.environment()
10
- const savedState = await Agent.state(scope)
10
+ const state = await Agent.state(scope)
11
11
 
12
12
  const scopedPaths = getScopedPaths(storeDefinition)
13
13
  const stateAttachedStore = await attachModuleState(savedState, storeDefinition, scopedPaths)
@@ -15,13 +15,15 @@ export default async function (storeDefinition) {
15
15
  const originalState = s instanceof Function ? s() : s
16
16
  const handlePatch = patch => Agent.interact(scope, patch)
17
17
 
18
- if (savedState === null) handlePatch([{ op: 'add', path: [], value: copy(originalState) }])
19
-
18
+ if (Object.entries(state).length === 0) {
19
+ state = copy(originalState)
20
+ handlePatch([{ op: 'add', path: [], value: state }])
21
+ }
20
22
  // ephemeral paths for the root mutable proxy are any paths with a scope specified (including null scopes)
21
23
  const ephemeralPaths = {}
22
24
  Object.keys(scopedPaths).forEach(key => ephemeralPaths[key] = true)
23
25
 
24
- stateAttachedStore.state = () => MutableProxy(savedState || originalState, handlePatch, ephemeralPaths)
26
+ stateAttachedStore.state = () => MutableProxy(state, handlePatch, ephemeralPaths)
25
27
  return stateAttachedStore
26
28
  }
27
29