dict: Remove setdefault method.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-02-02 21:49:12 -08:00
committed by Tim Abbott
parent 8872aca907
commit b16222a38b
3 changed files with 5 additions and 30 deletions

View File

@@ -110,20 +110,6 @@ run_test('each', () => {
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', () => {
const d = new Dict();
assert.equal(d.num_items(), 0);

View File

@@ -21,18 +21,6 @@ export class Dict<V> {
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 {
return _.has(this._items, this._munge(key));
}

View File

@@ -410,10 +410,11 @@ exports.get_message_reactions = function (message) {
return;
}
reaction.user_ids = [];
const collapsed_reaction = message_reactions.setdefault(
reaction.local_id,
_.omit(reaction, 'user')
);
let collapsed_reaction = message_reactions.get(reaction.local_id);
if (collapsed_reaction === undefined) {
collapsed_reaction = _.omit(reaction, 'user');
message_reactions.set(reaction.local_id, collapsed_reaction);
}
collapsed_reaction.user_ids.push(user_id);
});
const reactions = message_reactions.items().map(function (item) {