mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
dict: Replace items method with @@iterator method.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
9e1343ff8a
commit
fac2c71776
@@ -26,7 +26,7 @@ run_test('basic', () => {
|
|||||||
|
|
||||||
assert.deepEqual([...d.keys()], ['foo', 'bar']);
|
assert.deepEqual([...d.keys()], ['foo', 'bar']);
|
||||||
assert.deepEqual([...d.values()], ['baz', 'qux']);
|
assert.deepEqual([...d.values()], ['baz', 'qux']);
|
||||||
assert.deepEqual(d.items(), [['foo', 'baz'], ['bar', 'qux']]);
|
assert.deepEqual([...d], [['foo', 'baz'], ['bar', 'qux']]);
|
||||||
|
|
||||||
d.delete('bar');
|
d.delete('bar');
|
||||||
assert.equal(d.has('bar'), false);
|
assert.equal(d.has('bar'), false);
|
||||||
@@ -83,12 +83,12 @@ run_test('restricted_keys', () => {
|
|||||||
run_test('construction', () => {
|
run_test('construction', () => {
|
||||||
const d1 = new Dict();
|
const d1 = new Dict();
|
||||||
|
|
||||||
assert.deepEqual(d1.items(), []);
|
assert.deepEqual([...d1], []);
|
||||||
|
|
||||||
const d2 = new Dict();
|
const d2 = new Dict();
|
||||||
d2.set('foo', 'bar');
|
d2.set('foo', 'bar');
|
||||||
d2.set('baz', 'qux');
|
d2.set('baz', 'qux');
|
||||||
assert.deepEqual(d2.items(), [['foo', 'bar'], ['baz', 'qux']]);
|
assert.deepEqual([...d2], [['foo', 'bar'], ['baz', 'qux']]);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('each', () => {
|
run_test('each', () => {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ run_test('basic', () => {
|
|||||||
|
|
||||||
assert.deepEqual([...d.keys()], ['foo', 'bar']);
|
assert.deepEqual([...d.keys()], ['foo', 'bar']);
|
||||||
assert.deepEqual([...d.values()], ['baz', 'qux']);
|
assert.deepEqual([...d.values()], ['baz', 'qux']);
|
||||||
assert.deepEqual(d.items(), [['foo', 'baz'], ['bar', 'qux']]);
|
assert.deepEqual([...d], [['foo', 'baz'], ['bar', 'qux']]);
|
||||||
|
|
||||||
d.delete('bar');
|
d.delete('bar');
|
||||||
assert.equal(d.has('bar'), false);
|
assert.equal(d.has('bar'), false);
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ export class Dict<V> {
|
|||||||
return this._items.values();
|
return this._items.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
items(): [string, V][] {
|
[Symbol.iterator](): Iterator<[string, V]> {
|
||||||
return [...this._items];
|
return this._items.entries();
|
||||||
}
|
}
|
||||||
|
|
||||||
get size(): number {
|
get size(): number {
|
||||||
|
|||||||
@@ -50,8 +50,10 @@ export class FoldDict<V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
items(): [string, V][] {
|
*[Symbol.iterator](): Iterator<[string, V]> {
|
||||||
return [...this._items.values()].map(({k, v}) => [k, v]);
|
for (const {k, v} of this._items.values()) {
|
||||||
|
yield [k, v];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get size(): number {
|
get size(): number {
|
||||||
|
|||||||
@@ -417,8 +417,7 @@ exports.get_message_reactions = function (message) {
|
|||||||
}
|
}
|
||||||
collapsed_reaction.user_ids.push(user_id);
|
collapsed_reaction.user_ids.push(user_id);
|
||||||
});
|
});
|
||||||
const reactions = message_reactions.items().map(function (item) {
|
const reactions = Array.from(message_reactions.values(), reaction => {
|
||||||
const reaction = item[1];
|
|
||||||
reaction.local_id = reaction.local_id;
|
reaction.local_id = reaction.local_id;
|
||||||
reaction.reaction_type = reaction.reaction_type;
|
reaction.reaction_type = reaction.reaction_type;
|
||||||
reaction.emoji_name = reaction.emoji_name;
|
reaction.emoji_name = reaction.emoji_name;
|
||||||
|
|||||||
Reference in New Issue
Block a user