mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
util: Convert CachedValue to an ES6 class.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
4ad00c1aea
commit
aee95ecf7e
@@ -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)/);
|
||||||
|
|||||||
Reference in New Issue
Block a user