@live-change/dao-vue3 0.2.0 → 0.2.1

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/lib/live.js +18 -8
  2. package/package.json +2 -2
package/lib/live.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { ref, onUnmounted, getCurrentInstance, unref, reactive } from 'vue'
2
2
  import { collectPointers, ExtendedObservableList } from '@live-change/dao'
3
+ import nodeDebug from "debug"
4
+ const debug = nodeDebug('dao-vue3')
3
5
 
4
6
  const liveSymbol = Symbol('live')
5
7
 
@@ -18,7 +20,7 @@ async function live(api, path, onUnmountedCb) {
18
20
  const paths = [ path ]
19
21
  if(typeof window == 'undefined') {
20
22
  const preFetchPaths = await api.get({ paths })
21
- console.log("PRE FETCH DATA", preFetchPaths)
23
+ debug("PRE FETCH DATA", preFetchPaths)
22
24
  const preFetchMap = new Map(preFetchPaths.map((res) => [JSON.stringify(res.what), res] ))
23
25
  function createObject(what, more) {
24
26
  const res = preFetchMap.get(JSON.stringify(what))
@@ -29,13 +31,13 @@ async function live(api, path, onUnmountedCb) {
29
31
  for(let i = 0; i < data.length; i ++) {
30
32
  for(const moreElement of more) {
31
33
  if(moreElement.to) {
32
- console.log("COLLECT POINTERS FROM", data[i], "SC", moreElement.schema)
34
+ debug("COLLECT POINTERS FROM", data[i], "SC", moreElement.schema)
33
35
  const pointers = collectPointers(data[i], moreElement.schema ,
34
36
  (what) => preFetchMap.get(JSON.stringify(what)))
35
- console.log("POINTERS COLLECTED", pointers)
37
+ debug("POINTERS COLLECTED", pointers)
36
38
  const values = pointers.map(pointer => createObject(pointer, moreElement.more))
37
- console.log("VALUES", values)
38
- console.log("MANY", pointers.many)
39
+ debug("VALUES", values)
40
+ debug("MANY", pointers.many)
39
41
  if(pointers.many) {
40
42
  data[i][moreElement.to] = values
41
43
  } else {
@@ -148,7 +150,8 @@ async function live(api, path, onUnmountedCb) {
148
150
  }
149
151
  const propSources = prop.sources
150
152
  for(const propSource of propSources) {
151
- //console.log("PROP SOURCE DISPOSE", propSource)
153
+ debug("PROP SOURCE DISPOSE", propSource)
154
+ debug("UNOBSERVE PROPERTY", what, object, property)
152
155
  propSource.observable.unobserve(propSource.observer)
153
156
  }
154
157
  }
@@ -166,6 +169,7 @@ async function live(api, path, onUnmountedCb) {
166
169
  what,
167
170
  property,
168
171
  dispose() {
172
+ debug("UNBIND PROPERTY", what, object, property)
169
173
  extendedObservable.unbindProperty(object, property)
170
174
  }
171
175
  }
@@ -174,14 +178,20 @@ async function live(api, path, onUnmountedCb) {
174
178
  return {
175
179
  what, property,
176
180
  dispose() {
181
+ debug("UNBIND PROPERTY", what, object, property)
177
182
  observable.unbindProperty(object, property)
178
183
  }
179
184
  }
180
185
  }
181
186
  }
182
187
  const resultRef = ref()
183
- bindResult(path.what, path.more, resultRef, 'value')
184
- /// TODO: unobserve on unmounted
188
+ const bound = bindResult(path.what, path.more, resultRef, 'value')
189
+ const pathsObserver = (signal, value) => {}
190
+ preFetchPaths.observe(pathsObserver)
191
+ onUnmountedCb(() => {
192
+ preFetchPaths.unobserve(pathsObserver)
193
+ bound.dispose()
194
+ })
185
195
  await preFetchPaths.wait()
186
196
  while(unref(resultRef) === undefined) { // wait for next tick
187
197
  await new Promise((resolve) => setTimeout(resolve, 0))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/dao-vue3",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "author": {
5
5
  "email": "m8@em8.pl",
6
6
  "name": "Michał Łaszczewski",
@@ -10,7 +10,7 @@
10
10
  "url": "https://github.com/live-change/dao-vue3/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@live-change/dao": "^0.3.9"
13
+ "@live-change/dao": "^0.3.15"
14
14
  },
15
15
  "devDependencies": {},
16
16
  "description": "Vue.js integration for live-change dao",