@vaadin/component-base
Advanced tools
Comparing version 24.4.0-alpha1 to 24.4.0-dev.223e39f050
{ | ||
"name": "@vaadin/component-base", | ||
"version": "24.4.0-alpha1", | ||
"version": "24.4.0-dev.223e39f050", | ||
"publishConfig": { | ||
@@ -45,3 +45,3 @@ "access": "public" | ||
}, | ||
"gitHead": "3e2ed41c99d618ff7def2734fd863c21c85775a3" | ||
"gitHead": "5e2e3bfc811c95aed9354235fab93fdbf43eb354" | ||
} |
@@ -20,9 +20,2 @@ /** | ||
/** | ||
* The number of items. | ||
* | ||
* @type {number} | ||
*/ | ||
size = 0; | ||
/** | ||
* The number of items to display per page. | ||
@@ -63,2 +56,10 @@ * | ||
/** | ||
* The number of items. | ||
* | ||
* @type {number} | ||
* @private | ||
*/ | ||
__size = 0; | ||
/** | ||
* The total number of items, including items from expanded sub-caches. | ||
@@ -142,2 +143,42 @@ * | ||
/** | ||
* The number of items. | ||
* | ||
* @type {number} | ||
* @private | ||
*/ | ||
get size() { | ||
return this.__size; | ||
} | ||
/** | ||
* Sets the number of items. | ||
* | ||
* @type {number} | ||
* @private | ||
*/ | ||
set size(size) { | ||
const oldSize = this.__size; | ||
if (oldSize === size) { | ||
return; | ||
} | ||
this.__size = size; | ||
if (this.context.placeholder !== undefined) { | ||
this.items.length = size; | ||
for (let i = 0; i < size; i++) { | ||
// eslint-disable-next-line logical-assignment-operators | ||
this.items[i] = this.items[i] || this.context.placeholder; | ||
} | ||
} | ||
Object.keys(this.pendingRequests).forEach((page) => { | ||
const startIndex = parseInt(page) * this.pageSize; | ||
if (startIndex >= this.size) { | ||
delete this.pendingRequests[page]; | ||
} | ||
}); | ||
} | ||
/** | ||
* Recalculates the flattened size for the cache and its descendant caches recursively. | ||
@@ -144,0 +185,0 @@ */ |
@@ -68,3 +68,17 @@ /** | ||
constructor(host, { size, pageSize, isExpanded, getItemId, dataProvider, dataProviderParams }) { | ||
/** | ||
* Indicates whether any data has been loaded since the last cache clear. | ||
* | ||
* @type {boolean} | ||
*/ | ||
hasData = false; | ||
/** | ||
* A placeholder item that is used to indicate that the item is not loaded yet. | ||
* | ||
* @type {undefined | object} | ||
*/ | ||
placeholder; | ||
constructor(host, { size, pageSize, isExpanded, getItemId, placeholder, dataProvider, dataProviderParams }) { | ||
super(); | ||
@@ -75,2 +89,3 @@ this.host = host; | ||
this.isExpanded = isExpanded; | ||
this.placeholder = placeholder; | ||
this.dataProvider = dataProvider; | ||
@@ -92,2 +107,3 @@ this.dataProviderParams = dataProviderParams; | ||
isExpanded: this.isExpanded, | ||
placeholder: this.placeholder, | ||
// The controller instance is needed to ensure deprecated cache methods work. | ||
@@ -139,2 +155,3 @@ __controller: this, | ||
this.rootCache = this.__createRootCache(this.rootCache.size); | ||
this.hasData = false; | ||
} | ||
@@ -194,3 +211,3 @@ | ||
if (!item) { | ||
if (this.__isPlaceholder(item)) { | ||
this.__loadCachePage(cache, page); | ||
@@ -210,3 +227,3 @@ } | ||
if (item && this.isExpanded(item) && !cache.getSubCache(index)) { | ||
if (!this.__isPlaceholder(item) && this.isExpanded(item) && !cache.getSubCache(index)) { | ||
const subCache = cache.createSubCache(index); | ||
@@ -250,2 +267,4 @@ this.__loadCachePage(subCache, 0); | ||
cache.setPage(page, items); | ||
if (size !== undefined) { | ||
@@ -257,6 +276,6 @@ cache.size = size; | ||
cache.setPage(page, items); | ||
this.recalculateFlatSize(); | ||
this.hasData = true; | ||
this.dispatchEvent(new CustomEvent('page-received')); | ||
@@ -275,2 +294,7 @@ | ||
} | ||
/** @private */ | ||
__isPlaceholder(item) { | ||
return this.placeholder ? item === this.placeholder : !item; | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
210240
6284