From aee95ecf7e078d503485a70f7bbaf02a8dc1b26c Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 22 Jul 2020 15:29:05 -0700 Subject: [PATCH] util: Convert CachedValue to an ES6 class. Signed-off-by: Anders Kaseorg --- static/js/util.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/static/js/util.js b/static/js/util.js index 8710c33b8c..5a4a8bea24 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -176,23 +176,25 @@ exports.array_compare = function util_array_compare(a, b) { * which should be a function that computes the uncached value. */ const unassigned_value_sentinel = {}; -exports.CachedValue = function (opts) { - this._value = unassigned_value_sentinel; - Object.assign(this, opts); -}; +class CachedValue { + _value = unassigned_value_sentinel; -exports.CachedValue.prototype = { - get: function CachedValue_get() { + constructor(opts) { + Object.assign(this, opts); + } + + get() { if (this._value === unassigned_value_sentinel) { this._value = this.compute_value(); } return this._value; - }, + } - reset: function CachedValue_reset() { + reset() { this._value = unassigned_value_sentinel; - }, -}; + } +} +exports.CachedValue = CachedValue; exports.find_wildcard_mentions = function (message_content) { const mention = message_content.match(/(^|\s)(@\*{2}(all|everyone|stream)\*{2})($|\s)/);