@live-change/dao-vue3 0.1.21 → 0.1.22

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/RangeBuckets.js +21 -18
  2. package/package.json +1 -1
@@ -19,7 +19,11 @@ class Bucket {
19
19
  this.data = computed(() => {
20
20
  const ldv = this.liveData.value
21
21
  if(!ldv) return []
22
- const source = unref(ldv)
22
+ let source = unref(ldv)
23
+ if(this.range.reverse) {
24
+ source = source.slice()
25
+ source.reverse()
26
+ }
23
27
  if(this.hardClose) {
24
28
  return source
25
29
  }
@@ -46,16 +50,6 @@ class Bucket {
46
50
  this.dataPromise = live(this.api(), this.path, fun => onDispose.push(fun))
47
51
  this.dataPromise.then(data => {
48
52
  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
- // )))
59
53
  })
60
54
  return this.dataPromise
61
55
  }
@@ -77,14 +71,14 @@ class Bucket {
77
71
  const data = unref(await this.dataPromise)
78
72
  if(!this.data) throw new Error("can't close - bucket not loaded!")
79
73
  if(this.data.length < this.bucketSize) throw new Error("can't close - bucket not full")
80
- this.range.gte = data[0].id
74
+ this.range.gte = data[this.range.reverse ? data.length - 1 : 0].id
81
75
  if(this.hardClose) await this.load()
82
76
  }
83
77
 
84
78
  async closeBottom() {
85
79
  const data = unref(await this.dataPromise)
86
80
  if(data.length < this.bucketSize) throw new Error("can't close - bucket not full")
87
- this.range.lte = data[data.length - 1].id
81
+ this.range.lte = data[this.range.reverse ? 0 : data.length - 1].id
88
82
  if(this.hardClose) await this.load()
89
83
  }
90
84
 
@@ -140,17 +134,20 @@ class RangeBuckets {
140
134
  }
141
135
 
142
136
  async wait() {
143
- console.log("WAIT FOR BUCKETS", this.buckets.length)
137
+ //console.log("WAIT FOR BUCKETS", this.buckets.length)
144
138
  await Promise.all(this.buckets.map(bucket => bucket.promise)).then(loaded => this)
145
139
  }
146
140
 
147
141
  async loadTop() {
142
+ //console.log("LOAD TOP!", this.isTopLoadPossible())
148
143
  if(this.buckets.length == 0) return this.loadFirstBucket()
149
144
  const firstBucket = this.buckets[0]
150
145
  await firstBucket.promise
151
146
  if(!this.isTopLoadPossible()) return
152
- if(firstBucket != this.buckets[0]) return this.buckets[0].promise
153
- let range = { limit: this.bucketSize }
147
+ if(firstBucket != this.buckets[0]) {
148
+ return this.buckets[0].promise
149
+ }
150
+ let range = { limit: this.bucketSize, reverse: true }
154
151
  if(!firstBucket.isTopClosed()) {
155
152
  if(firstBucket.canClose()) {
156
153
  await firstBucket.closeTop()
@@ -175,11 +172,14 @@ class RangeBuckets {
175
172
  }
176
173
 
177
174
  async loadBottom() {
175
+ //console.log("LOAD BOTTOM!", this.isBottomLoadPossible())
178
176
  if(this.buckets.length == 0) return this.loadFirstBucket()
179
177
  const lastBucket = this.buckets[this.buckets.length - 1]
180
178
  await lastBucket.promise
181
179
  if(!this.isBottomLoadPossible()) return
182
- if(lastBucket != this.buckets[this.buckets.length - 1]) return this.buckets[this.buckets.length - 1].promise
180
+ if(lastBucket != this.buckets[this.buckets.length - 1]) {
181
+ return this.buckets[this.buckets.length - 1].promise
182
+ }
183
183
  let range = { limit: this.bucketSize }
184
184
  if(!lastBucket.isBottomClosed()) {
185
185
  if(lastBucket.canClose()) {
@@ -205,14 +205,17 @@ class RangeBuckets {
205
205
 
206
206
  dropTop() {
207
207
  if(this.buckets.length == 0) throw new Error('impossible to drop from empty')
208
+ //console.log("DROP TOP!")
208
209
  const droppedBucket = this.buckets[0]
209
- const height = droppedBucket.domElements.reduce((acc, el) => acc + el?.offsetHeight, 0)
210
+ const height = droppedBucket.domElements.reduce((acc, el) => acc + (el?.offsetHeight || 0), 0)
211
+ //console.log("DOM ELEMENTS", droppedBucket.domElements.map(el => el?.offsetHeight || 0), height)
210
212
  this.buckets.shift()
211
213
  droppedBucket.dispose()
212
214
  return height
213
215
  }
214
216
 
215
217
  dropBottom() {
218
+ //console.log("DROP BOTTOM!")
216
219
  if(this.buckets.length == 0) throw new Error('impossible to drop from empty')
217
220
  const droppedBucket = this.buckets[this.buckets.length - 1]
218
221
  const height = droppedBucket.domElements.reduce((acc, el) => acc + el?.offsetHeight, 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/dao-vue3",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "author": {
5
5
  "email": "m8@em8.pl",
6
6
  "name": "Michał Łaszczewski",