@live-change/dao-vue3 0.1.19 → 0.1.20

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.
@@ -1,5 +1,5 @@
1
1
  import live from "./live.js"
2
- import { computed, reactive, unref } from "vue"
2
+ import { computed, reactive, ref, unref, watch } from "vue"
3
3
 
4
4
  class Bucket {
5
5
 
@@ -16,7 +16,22 @@ class Bucket {
16
16
  this.onDispose = []
17
17
  this.domElements = []
18
18
 
19
- this.data = undefined
19
+ this.data = computed(() => {
20
+ const ldv = this.liveData.value
21
+ if(!ldv) return []
22
+ const source = unref(ldv)
23
+ if(this.hardClose) {
24
+ return source
25
+ }
26
+ return source.filter(element => (
27
+ (!this.range.gt || element.id > this.range.gt ) &&
28
+ (!this.range.gte || element.id >= this.range.gte) &&
29
+ (!this.range.lt || element.id < this.range.lt ) &&
30
+ (!this.range.lte || element.id <= this.range.lte)
31
+ ))
32
+ })
33
+ this.liveData = ref(null)
34
+
20
35
  this.load()
21
36
 
22
37
  this.promise = waitForComponents ? this.createPromise() : this.dataPromise
@@ -30,16 +45,17 @@ class Bucket {
30
45
  this.path = this.pathFunction(this.range)
31
46
  this.dataPromise = live(this.api(), this.path, fun => onDispose.push(fun))
32
47
  this.dataPromise.then(data => {
33
- if(this.hardClose) {
34
- this.data = data
35
- return
36
- }
37
- this.data = computed(() => data.filter(element => (
38
- (!this.range.gt || element.id > this.range.gt ) &&
39
- (!this.range.gte || element.id >= this.range.gte) &&
40
- (!this.range.lt || element.id < this.range.lt ) &&
41
- (!this.range.lte || element.id <= this.range.lte)
42
- )))
48
+ this.liveData.value = data
49
+ // if(this.hardClose) {
50
+ // this.data.value = this.liveData.value
51
+ // return
52
+ // }
53
+ // return this.data.value = computed(() => source.filter(element => (
54
+ // (!this.range.gt || element.id > this.range.gt ) &&
55
+ // (!this.range.gte || element.id >= this.range.gte) &&
56
+ // (!this.range.lt || element.id < this.range.lt ) &&
57
+ // (!this.range.lte || element.id <= this.range.lte)
58
+ // )))
43
59
  })
44
60
  return this.dataPromise
45
61
  }
@@ -92,9 +108,24 @@ class RangeBuckets {
92
108
  this.lastBucketId = 0
93
109
  this.buckets = reactive([])
94
110
 
111
+ this.canLoadTop = computed(() => this.isTopLoadPossible())
112
+ this.canLoadBottom = computed(() => this.isBottomLoadPossible())
113
+
95
114
  this.loadFirstBucket()
96
115
  }
97
116
 
117
+ isTopLoadPossible() {
118
+ if(this.buckets.length == 0) return false
119
+ const firstBucket = this.buckets[0]
120
+ return firstBucket.isTopClosed() || firstBucket.canClose()
121
+ }
122
+
123
+ isBottomLoadPossible() {
124
+ if(this.buckets.length == 0) return false
125
+ const lastBucket = this.buckets[this.buckets.length - 1]
126
+ return lastBucket.isBottomClosed() || lastBucket.canClose()
127
+ }
128
+
98
129
  loadFirstBucket() {
99
130
  const firstBucket = this.createBucket({
100
131
  gte: this.position,
@@ -109,32 +140,22 @@ class RangeBuckets {
109
140
  }
110
141
 
111
142
  async wait() {
143
+ console.log("WAIT FOR BUCKETS", this.buckets.length)
112
144
  await Promise.all(this.buckets.map(bucket => bucket.promise)).then(loaded => this)
113
145
  }
114
146
 
115
- canLoadTop() {
116
- if(this.buckets.length == 0) return false
117
- const firstBucket = this.buckets[0]
118
- return firstBucket.isTopClosed() || firstBucket.canClose()
119
- }
120
-
121
- canLoadBottom() {
122
- if(this.buckets.length == 0) return false
123
- const lastBucket = this.buckets[this.buckets.length - 1]
124
- return lastBucket.isBottomClosed() || lastBucket.canClose()
125
- }
126
-
127
147
  async loadTop() {
128
148
  if(this.buckets.length == 0) return this.loadFirstBucket()
129
149
  const firstBucket = this.buckets[0]
130
150
  await firstBucket.promise
131
- if(!this.canLoadTop()) return
151
+ if(!this.isTopLoadPossible()) return
132
152
  if(firstBucket != this.buckets[0]) return this.buckets[0].promise
133
153
  let range = { limit: this.bucketSize }
134
154
  if(!firstBucket.isTopClosed()) {
135
155
  if(firstBucket.canClose()) {
136
156
  await firstBucket.closeTop()
137
- if(!this.canLoadTop()) return
157
+ if(!firstBucket.isTopClosed()) throw new Error('top not closed!!!')
158
+ if(!this.isTopLoadPossible()) return
138
159
  return this.loadTop()
139
160
  } else {
140
161
  console.log("FBD", unref(firstBucket.data))
@@ -157,13 +178,14 @@ class RangeBuckets {
157
178
  if(this.buckets.length == 0) return this.loadFirstBucket()
158
179
  const lastBucket = this.buckets[this.buckets.length - 1]
159
180
  await lastBucket.promise
160
- if(!this.canLoadBottom()) return
181
+ if(!this.isBottomLoadPossible()) return
161
182
  if(lastBucket != this.buckets[this.buckets.length - 1]) return this.buckets[this.buckets.length - 1].promise
162
183
  let range = { limit: this.bucketSize }
163
184
  if(!lastBucket.isBottomClosed()) {
164
185
  if(lastBucket.canClose()) {
165
186
  await lastBucket.closeBottom()
166
187
  if(!lastBucket.isBottomClosed()) throw new Error('bottom not closed!!!')
188
+ if(!this.isBottomLoadPossible()) return
167
189
  return this.loadBottom()
168
190
  } else {
169
191
  throw new Error('impossible to read after bucket that is not closeable')
package/lib/live.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ref, onUnmounted, getCurrentInstance, unref, nextTick } from 'vue'
1
+ import { ref, onUnmounted, getCurrentInstance, unref, reactive } from 'vue'
2
2
  import { collectPointers, ExtendedObservableList } from '@live-change/dao'
3
3
 
4
4
  const liveSymbol = Symbol('live')
@@ -152,6 +152,13 @@ async function live(api, path, onUnmountedCb) {
152
152
  propSource.observable.unobserve(propSource.observer)
153
153
  }
154
154
  }
155
+ },
156
+ (data) => {
157
+ if(data && typeof data == 'object') {
158
+ const activated = reactive(data)
159
+ return activated
160
+ }
161
+ return data
155
162
  }
156
163
  )
157
164
  extendedObservable.bindProperty(object, property)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/dao-vue3",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
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.2.41"
13
+ "@live-change/dao": "^0.3.9"
14
14
  },
15
15
  "devDependencies": {},
16
16
  "description": "Vue.js integration for live-change dao",