util: Convert CachedValue to an ES6 class.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-07-22 15:29:05 -07:00
committed by Tim Abbott
parent 4ad00c1aea
commit aee95ecf7e

View File

@@ -176,23 +176,25 @@ exports.array_compare = function util_array_compare(a, b) {
* which should be a function that computes the uncached value. * which should be a function that computes the uncached value.
*/ */
const unassigned_value_sentinel = {}; const unassigned_value_sentinel = {};
exports.CachedValue = function (opts) { class CachedValue {
this._value = unassigned_value_sentinel; _value = unassigned_value_sentinel;
Object.assign(this, opts);
};
exports.CachedValue.prototype = { constructor(opts) {
get: function CachedValue_get() { Object.assign(this, opts);
}
get() {
if (this._value === unassigned_value_sentinel) { if (this._value === unassigned_value_sentinel) {
this._value = this.compute_value(); this._value = this.compute_value();
} }
return this._value; return this._value;
}, }
reset: function CachedValue_reset() { reset() {
this._value = unassigned_value_sentinel; this._value = unassigned_value_sentinel;
}, }
}; }
exports.CachedValue = CachedValue;
exports.find_wildcard_mentions = function (message_content) { exports.find_wildcard_mentions = function (message_content) {
const mention = message_content.match(/(^|\s)(@\*{2}(all|everyone|stream)\*{2})($|\s)/); const mention = message_content.match(/(^|\s)(@\*{2}(all|everyone|stream)\*{2})($|\s)/);