dict: Remove Dict.from.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-02-03 05:46:13 +00:00
committed by Tim Abbott
parent 5b824702b4
commit 52765796c2
2 changed files with 3 additions and 27 deletions

View File

@@ -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) {

View File

@@ -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.