@vaadin/component-base 24.3.2 → 24.4.0-dev.223e39f050

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": "@vaadin/component-base",
3
- "version": "24.3.2",
3
+ "version": "24.4.0-dev.223e39f050",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,5 +42,5 @@
42
42
  "@vaadin/testing-helpers": "^0.6.0",
43
43
  "sinon": "^13.0.2"
44
44
  },
45
- "gitHead": "615ee9dd4611f52db90445b0db13dcbb91ca74d4"
45
+ "gitHead": "5e2e3bfc811c95aed9354235fab93fdbf43eb354"
46
46
  }
@@ -16,13 +16,6 @@ export class Cache {
16
16
  */
17
17
  context;
18
18
 
19
- /**
20
- * The number of items.
21
- *
22
- * @type {number}
23
- */
24
- size = 0;
25
-
26
19
  /**
27
20
  * The number of items to display per page.
28
21
  *
@@ -58,6 +51,14 @@ export class Cache {
58
51
  */
59
52
  __subCacheByIndex = {};
60
53
 
54
+ /**
55
+ * The number of items.
56
+ *
57
+ * @type {number}
58
+ * @private
59
+ */
60
+ __size = 0;
61
+
61
62
  /**
62
63
  * The total number of items, including items from expanded sub-caches.
63
64
  *
@@ -136,6 +137,46 @@ export class Cache {
136
137
  return this.flatSize;
137
138
  }
138
139
 
140
+ /**
141
+ * The number of items.
142
+ *
143
+ * @type {number}
144
+ * @private
145
+ */
146
+ get size() {
147
+ return this.__size;
148
+ }
149
+
150
+ /**
151
+ * Sets the number of items.
152
+ *
153
+ * @type {number}
154
+ * @private
155
+ */
156
+ set size(size) {
157
+ const oldSize = this.__size;
158
+ if (oldSize === size) {
159
+ return;
160
+ }
161
+
162
+ this.__size = size;
163
+
164
+ if (this.context.placeholder !== undefined) {
165
+ this.items.length = size;
166
+ for (let i = 0; i < size; i++) {
167
+ // eslint-disable-next-line logical-assignment-operators
168
+ this.items[i] = this.items[i] || this.context.placeholder;
169
+ }
170
+ }
171
+
172
+ Object.keys(this.pendingRequests).forEach((page) => {
173
+ const startIndex = parseInt(page) * this.pageSize;
174
+ if (startIndex >= this.size) {
175
+ delete this.pendingRequests[page];
176
+ }
177
+ });
178
+ }
179
+
139
180
  /**
140
181
  * Recalculates the flattened size for the cache and its descendant caches recursively.
141
182
  */
@@ -65,12 +65,27 @@ export class DataProviderController extends EventTarget {
65
65
  */
66
66
  rootCache;
67
67
 
68
- constructor(host, { size, pageSize, isExpanded, getItemId, dataProvider, dataProviderParams }) {
68
+ /**
69
+ * Indicates whether any data has been loaded since the last cache clear.
70
+ *
71
+ * @type {boolean}
72
+ */
73
+ hasData = false;
74
+
75
+ /**
76
+ * A placeholder item that is used to indicate that the item is not loaded yet.
77
+ *
78
+ * @type {undefined | object}
79
+ */
80
+ placeholder;
81
+
82
+ constructor(host, { size, pageSize, isExpanded, getItemId, placeholder, dataProvider, dataProviderParams }) {
69
83
  super();
70
84
  this.host = host;
71
85
  this.pageSize = pageSize;
72
86
  this.getItemId = getItemId;
73
87
  this.isExpanded = isExpanded;
88
+ this.placeholder = placeholder;
74
89
  this.dataProvider = dataProvider;
75
90
  this.dataProviderParams = dataProviderParams;
76
91
  this.rootCache = this.__createRootCache(size);
@@ -87,6 +102,7 @@ export class DataProviderController extends EventTarget {
87
102
  get __cacheContext() {
88
103
  return {
89
104
  isExpanded: this.isExpanded,
105
+ placeholder: this.placeholder,
90
106
  // The controller instance is needed to ensure deprecated cache methods work.
91
107
  __controller: this,
92
108
  };
@@ -133,6 +149,7 @@ export class DataProviderController extends EventTarget {
133
149
  */
134
150
  clearCache() {
135
151
  this.rootCache = this.__createRootCache(this.rootCache.size);
152
+ this.hasData = false;
136
153
  }
137
154
 
138
155
  /**
@@ -187,7 +204,7 @@ export class DataProviderController extends EventTarget {
187
204
  ensureFlatIndexLoaded(flatIndex) {
188
205
  const { cache, page, item } = this.getFlatIndexContext(flatIndex);
189
206
 
190
- if (!item) {
207
+ if (this.__isPlaceholder(item)) {
191
208
  this.__loadCachePage(cache, page);
192
209
  }
193
210
  }
@@ -202,7 +219,7 @@ export class DataProviderController extends EventTarget {
202
219
  ensureFlatIndexHierarchy(flatIndex) {
203
220
  const { cache, item, index } = this.getFlatIndexContext(flatIndex);
204
221
 
205
- if (item && this.isExpanded(item) && !cache.getSubCache(index)) {
222
+ if (!this.__isPlaceholder(item) && this.isExpanded(item) && !cache.getSubCache(index)) {
206
223
  const subCache = cache.createSubCache(index);
207
224
  this.__loadCachePage(subCache, 0);
208
225
  }
@@ -237,16 +254,22 @@ export class DataProviderController extends EventTarget {
237
254
  }
238
255
 
239
256
  const callback = (items, size) => {
257
+ if (cache.pendingRequests[page] !== callback) {
258
+ return;
259
+ }
260
+
261
+ cache.setPage(page, items);
262
+
240
263
  if (size !== undefined) {
241
264
  cache.size = size;
242
265
  } else if (params.parentItem) {
243
266
  cache.size = items.length;
244
267
  }
245
268
 
246
- cache.setPage(page, items);
247
-
248
269
  this.recalculateFlatSize();
249
270
 
271
+ this.hasData = true;
272
+
250
273
  this.dispatchEvent(new CustomEvent('page-received'));
251
274
 
252
275
  delete cache.pendingRequests[page];
@@ -260,4 +283,9 @@ export class DataProviderController extends EventTarget {
260
283
 
261
284
  this.dataProvider(params, callback);
262
285
  }
286
+
287
+ /** @private */
288
+ __isPlaceholder(item) {
289
+ return this.placeholder ? item === this.placeholder : !item;
290
+ }
263
291
  }
package/src/define.js CHANGED
@@ -9,7 +9,7 @@ export function defineCustomElement(CustomElement) {
9
9
  if (!defined) {
10
10
  Object.defineProperty(CustomElement, 'version', {
11
11
  get() {
12
- return '24.3.2';
12
+ return '24.4.0-alpha1';
13
13
  },
14
14
  });
15
15