mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
dict: Remove Dict.from.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
5b824702b4
commit
52765796c2
@@ -85,7 +85,9 @@ run_test('construction', () => {
|
||||
|
||||
assert.deepEqual(d1.items(), []);
|
||||
|
||||
const d2 = Dict.from({foo: 'bar', baz: 'qux'});
|
||||
const d2 = new Dict();
|
||||
d2.set('foo', 'bar');
|
||||
d2.set('baz', 'qux');
|
||||
assert.deepEqual(d2.items(), [['foo', 'bar'], ['baz', 'qux']]);
|
||||
|
||||
const d3 = d2.clone();
|
||||
@@ -97,15 +99,6 @@ run_test('construction', () => {
|
||||
assert.deepEqual(d4.items(), [['foo', true], ['bar', true]]);
|
||||
|
||||
let caught;
|
||||
try {
|
||||
Dict.from('bogus');
|
||||
} catch (e) {
|
||||
caught = true;
|
||||
assert.equal(e.toString(), 'TypeError: Cannot convert argument to Dict');
|
||||
}
|
||||
assert(caught);
|
||||
|
||||
caught = undefined;
|
||||
try {
|
||||
Dict.from_array({bogus: true});
|
||||
} catch (e2) {
|
||||
|
||||
@@ -8,23 +8,6 @@ type Items<V> = {
|
||||
export class Dict<V> {
|
||||
private _items: Items<V> = {};
|
||||
|
||||
/**
|
||||
* Constructs a Dict object from an existing object's keys and values.
|
||||
* @param obj - A javascript object
|
||||
*/
|
||||
static from<V>(obj: { [key: string]: V }): Dict<V> {
|
||||
if (typeof obj !== "object" || obj === null) {
|
||||
throw new TypeError("Cannot convert argument to Dict");
|
||||
}
|
||||
|
||||
const dict = new Dict<V>();
|
||||
_.each(obj, function (val: V, key: string) {
|
||||
dict.set(key, val);
|
||||
});
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Dict object from an array with each element set to `true`.
|
||||
* Intended for use as a set data structure.
|
||||
|
||||
Reference in New Issue
Block a user