src/plugins/easycurrency/MoneySpanSet.js
/**
* Represents a unique set of MoneySpan objects.
*/
export default class MoneySpanSet {
/**
* Create an empty MoneySpanSet.
*/
constructor() {
/** @type {Object<String, MoneySpan>} */
this._spansByElement = new WeakMap();
this._allSpans = [];
}
/**
* Add a new span to the set.
* @param {src/plugins/easycurrency/MoneySpan.js~MoneySpan} moneySpan - Span to add
*/
add(moneySpan) {
this._spansByElement.set(moneySpan.getElement(), moneySpan);
this._allSpans.push(moneySpan);
}
/**
* Find a span by the element it renders to.
* @param {type} element - The element the span renders to.
* @return {undefined|src/plugins/easycurrency/MoneySpan.js~MoneySpan}
*/
findByElement(element) {
return this._spansByElement.get(element);
}
/**
* Returns a list of all the spans in the set.
* @return {MoneySpan[]}
*/
list() {
return this._allSpans;
}
}