@live-change/dao-vue3 0.1.22 → 0.4.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.
@@ -47,7 +47,7 @@ class Bucket {
47
47
 
48
48
  async load() {
49
49
  this.path = this.pathFunction(this.range)
50
- this.dataPromise = live(this.api(), this.path, fun => onDispose.push(fun))
50
+ this.dataPromise = live(this.api(), this.path, fun => this.onDispose.push(fun))
51
51
  this.dataPromise.then(data => {
52
52
  this.liveData.value = data
53
53
  })
@@ -134,7 +134,8 @@ class RangeBuckets {
134
134
  }
135
135
 
136
136
  async wait() {
137
- //console.log("WAIT FOR BUCKETS", this.buckets.length)
137
+ // console.log("WAIT FOR BUCKETS", this.buckets.length)
138
+ // console.log("BUCKET", this.buckets)
138
139
  await Promise.all(this.buckets.map(bucket => bucket.promise)).then(loaded => this)
139
140
  }
140
141
 
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,24 +20,24 @@ 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))
25
27
  if(res.error) throw new Error(res.error)
26
28
  const data = res.data
27
- if(more) {
29
+ if(data && more) {
28
30
  if(Array.isArray(data)) {
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 {
@@ -59,7 +61,7 @@ async function live(api, path, onUnmountedCb) {
59
61
  }
60
62
  }
61
63
  }
62
- return data
64
+ return ref(data)
63
65
  }
64
66
  return createObject(path.what, path.more)
65
67
  } 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,21 +1,20 @@
1
1
  {
2
2
  "name": "@live-change/dao-vue3",
3
- "version": "0.1.22",
3
+ "version": "0.4.1",
4
4
  "author": {
5
5
  "email": "m8@em8.pl",
6
6
  "name": "Michał Łaszczewski",
7
7
  "url": "http://www.viamage.com/"
8
8
  },
9
9
  "bugs": {
10
- "url": "https://github.com/live-change/dao-vue3/issues"
10
+ "url": "https://github.com/live-change/live-change-dao/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@live-change/dao": "^0.3.9"
13
+ "@live-change/dao": "^0.4.1"
14
14
  },
15
- "devDependencies": {},
16
15
  "description": "Vue.js integration for live-change dao",
17
16
  "directories": {},
18
- "homepage": "https://github.com/live-change/dao-vue3",
17
+ "homepage": "https://github.com/live-change/live-change-dao",
19
18
  "license": "MIT",
20
19
  "main": "index.js",
21
20
  "module": "index.js",
@@ -25,7 +24,6 @@
25
24
  "name": "Michał Łaszczewski"
26
25
  }
27
26
  ],
28
- "optionalDependencies": {},
29
27
  "readme": "README.md",
30
28
  "repository": {
31
29
  "type": "git",
@@ -33,5 +31,6 @@
33
31
  },
34
32
  "scripts": {
35
33
  "compileTests": "webpack test/*.js tests-bundle.js"
36
- }
34
+ },
35
+ "gitHead": "ea2d38a0401c1405bb3ca011a43a50dc7ada6cf6"
37
36
  }