@danielgindi/selectbox 1.0.66 → 1.0.69

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/dist/lib.es6.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 1.0.66
2
+ * @danielgindi/selectbox 1.0.69
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
@@ -2574,6 +2574,7 @@ class SelectBox {
2574
2574
  }
2575
2575
 
2576
2576
  this.setItems(o.items);
2577
+ delete o.items; // we do not need this in memory anymore
2577
2578
 
2578
2579
  if (o.multi && Array.isArray(o.selectedValues)) {
2579
2580
  this.setSelectedValues(o.selectedValues);
@@ -2725,6 +2726,8 @@ class SelectBox {
2725
2726
  p.filteredItems = null;
2726
2727
  p.itemsChanged = true;
2727
2728
 
2729
+ this._updateItemByValueMap();
2730
+
2728
2731
  if (resetValues) {
2729
2732
  this.setSelectedValues(this.getSelectedValues());
2730
2733
  }
@@ -2754,9 +2757,9 @@ class SelectBox {
2754
2757
  }
2755
2758
 
2756
2759
  updateItemByValue(value, newItem) {
2757
- const p = this._p, valueProp = p.valueProp;
2760
+ const p = this._p;
2758
2761
 
2759
- let existingItem = p.items.find(x => x[valueProp] === value);
2762
+ let existingItem = p.itemByValueMap.get(value);
2760
2763
  if (existingItem)
2761
2764
  Object.assign(existingItem, newItem);
2762
2765
 
@@ -3278,11 +3281,17 @@ class SelectBox {
3278
3281
  */
3279
3282
  setValueProp(prop) {
3280
3283
  const p = this._p;
3284
+
3285
+ if (p.valueProp === prop)
3286
+ return this;
3287
+
3281
3288
  p.valueProp = prop;
3282
3289
 
3283
3290
  if (p.dropList)
3284
3291
  p.dropList.setValueProp(prop);
3285
3292
 
3293
+ this._updateItemByValueMap();
3294
+
3286
3295
  return this;
3287
3296
  }
3288
3297
 
@@ -3434,7 +3443,7 @@ class SelectBox {
3434
3443
 
3435
3444
  selectedValues.push(value);
3436
3445
 
3437
- let item = p.items.find(x => x[valueProp] === value);
3446
+ let item = p.itemByValueMap.get(value);
3438
3447
  if (item !== undefined) {
3439
3448
  selectedItems.push(item);
3440
3449
  } else {
@@ -3655,6 +3664,21 @@ class SelectBox {
3655
3664
  return this;
3656
3665
  }
3657
3666
 
3667
+ /**
3668
+ * Prepare the mapping between values and items.
3669
+ * This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
3670
+ * @private
3671
+ */
3672
+ _updateItemByValueMap() {
3673
+ const p = this._p;
3674
+
3675
+ const itemByValueMap = p.itemByValueMap = new Map();
3676
+ const valueProp = p.valueProp;
3677
+ for (let item of p.items) {
3678
+ itemByValueMap.set(item[valueProp], item);
3679
+ }
3680
+ }
3681
+
3658
3682
  /** @private */
3659
3683
  _renderBase() {
3660
3684
  const p = this._p;
@@ -5429,6 +5453,11 @@ class SelectBox {
5429
5453
  stickyGroup = groups[0].filter(x => stickyValues.has(x[valueProp]));
5430
5454
  if (stickyGroup.length > 0) {
5431
5455
  groups[0] = groups[0].filter(x => !stickyValues.has(x[valueProp]));
5456
+
5457
+ if (groups[0].length === 0)
5458
+ groups.shift();
5459
+ } else {
5460
+ stickyGroup = null;
5432
5461
  }
5433
5462
  }
5434
5463
 
@@ -5453,7 +5482,7 @@ class SelectBox {
5453
5482
  });
5454
5483
  }
5455
5484
 
5456
- if (stickyGroup && stickyGroup.length > 0) {
5485
+ if (stickyGroup) {
5457
5486
  groups.unshift(stickyGroup);
5458
5487
  }
5459
5488