mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
dict: Remove setdefault method.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
8872aca907
commit
b16222a38b
@@ -110,20 +110,6 @@ run_test('each', () => {
|
|||||||
assert.equal(unseen_keys.length, 0);
|
assert.equal(unseen_keys.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('setdefault', () => {
|
|
||||||
const d = new Dict();
|
|
||||||
const val = ['foo'];
|
|
||||||
let res = d.setdefault('foo', val);
|
|
||||||
assert.equal(res, val);
|
|
||||||
assert.equal(d.has('foo'), true);
|
|
||||||
assert.equal(d.get('foo'), val);
|
|
||||||
|
|
||||||
const val2 = ['foo2'];
|
|
||||||
res = d.setdefault('foo', val2);
|
|
||||||
assert.equal(res, val);
|
|
||||||
assert.equal(d.get('foo'), val);
|
|
||||||
});
|
|
||||||
|
|
||||||
run_test('num_items', () => {
|
run_test('num_items', () => {
|
||||||
const d = new Dict();
|
const d = new Dict();
|
||||||
assert.equal(d.num_items(), 0);
|
assert.equal(d.num_items(), 0);
|
||||||
|
|||||||
@@ -21,18 +21,6 @@ export class Dict<V> {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* If `key` exists in the Dict, return its value. Otherwise insert `key`
|
|
||||||
* with a value of `value` and return the value.
|
|
||||||
*/
|
|
||||||
setdefault(key: string, value: V): V {
|
|
||||||
const mapping = this._items[this._munge(key)];
|
|
||||||
if (mapping === undefined) {
|
|
||||||
return this.set(key, value);
|
|
||||||
}
|
|
||||||
return mapping.v;
|
|
||||||
}
|
|
||||||
|
|
||||||
has(key: string): boolean {
|
has(key: string): boolean {
|
||||||
return _.has(this._items, this._munge(key));
|
return _.has(this._items, this._munge(key));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -410,10 +410,11 @@ exports.get_message_reactions = function (message) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
reaction.user_ids = [];
|
reaction.user_ids = [];
|
||||||
const collapsed_reaction = message_reactions.setdefault(
|
let collapsed_reaction = message_reactions.get(reaction.local_id);
|
||||||
reaction.local_id,
|
if (collapsed_reaction === undefined) {
|
||||||
_.omit(reaction, 'user')
|
collapsed_reaction = _.omit(reaction, 'user');
|
||||||
);
|
message_reactions.set(reaction.local_id, collapsed_reaction);
|
||||||
|
}
|
||||||
collapsed_reaction.user_ids.push(user_id);
|
collapsed_reaction.user_ids.push(user_id);
|
||||||
});
|
});
|
||||||
const reactions = message_reactions.items().map(function (item) {
|
const reactions = message_reactions.items().map(function (item) {
|
||||||
|
|||||||
Reference in New Issue
Block a user