From 52765796c2a663bfbe48922dacda8944354bbab4 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 3 Feb 2020 05:46:13 +0000 Subject: [PATCH] dict: Remove Dict.from. Signed-off-by: Anders Kaseorg --- frontend_tests/node_tests/dict.js | 13 +++---------- static/js/dict.ts | 17 ----------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/frontend_tests/node_tests/dict.js b/frontend_tests/node_tests/dict.js index 200f904b71..64305922a6 100644 --- a/frontend_tests/node_tests/dict.js +++ b/frontend_tests/node_tests/dict.js @@ -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) { diff --git a/static/js/dict.ts b/static/js/dict.ts index 0a6cd844f0..f2a8287bcf 100644 --- a/static/js/dict.ts +++ b/static/js/dict.ts @@ -8,23 +8,6 @@ type Items = { export class Dict { private _items: Items = {}; - /** - * Constructs a Dict object from an existing object's keys and values. - * @param obj - A javascript object - */ - static from(obj: { [key: string]: V }): Dict { - if (typeof obj !== "object" || obj === null) { - throw new TypeError("Cannot convert argument to Dict"); - } - - const dict = new Dict(); - _.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.