* Adds a new item to the map. * @param {String} key The key of the host * @param {Host} value The host to be added * @fires HostMap#remove * @fires HostMap#add
(key, value)
| 556 | * @fires HostMap#add |
| 557 | */ |
| 558 | set(key, value) { |
| 559 | // Clear values cache |
| 560 | this._values = null; |
| 561 | |
| 562 | const originalValue = this._items.get(key); |
| 563 | if (originalValue) { |
| 564 | //The internal structure does not change |
| 565 | this._items.set(key, value); |
| 566 | //emit a remove followed by a add |
| 567 | this.emit('remove', originalValue); |
| 568 | this.emit('add', value); |
| 569 | return; |
| 570 | } |
| 571 | |
| 572 | // Copy the values |
| 573 | const copy = new Map(this._items); |
| 574 | copy.set(key, value); |
| 575 | this._items = copy; |
| 576 | this.emit('add', value); |
| 577 | return value; |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Returns a shallow copy of a portion of the items into a new array object. |
no test coverage detected