diff --git a/frontend_tests/node_tests/widgetize.js b/frontend_tests/node_tests/widgetize.js index b8bf6fe008..fcc7bb603a 100644 --- a/frontend_tests/node_tests/widgetize.js +++ b/frontend_tests/node_tests/widgetize.js @@ -96,14 +96,14 @@ run_test('activate', () => { is_widget_elem_inserted = false; is_widget_activated = false; is_event_handled = false; - assert.equal(widgetize.widget_contents[opts.message.id], undefined); + assert(!widgetize.widget_contents.has(opts.message.id)); widgetize.activate(opts); assert(is_widget_elem_inserted); assert(is_widget_activated); assert(is_event_handled); - assert.equal(widgetize.widget_contents[opts.message.id], widget_elem); + assert.equal(widgetize.widget_contents.get(opts.message.id), widget_elem); is_widget_elem_inserted = false; is_widget_activated = false; diff --git a/static/js/widgetize.js b/static/js/widgetize.js index 09c8ef436a..637ed4fc0e 100644 --- a/static/js/widgetize.js +++ b/static/js/widgetize.js @@ -5,7 +5,7 @@ const widgets = new Map([ ["zform", zform], ]); -const widget_contents = {}; +const widget_contents = new Map(); exports.widget_contents = widget_contents; function set_widget_in_message(row, widget_elem) { @@ -41,7 +41,7 @@ exports.activate = function (in_opts) { return; } - let widget_elem = widget_contents[message.id]; + let widget_elem = widget_contents.get(message.id); if (widget_elem) { set_widget_in_message(row, widget_elem); return; @@ -58,7 +58,7 @@ exports.activate = function (in_opts) { extra_data: extra_data, }); - widget_contents[message.id] = widget_elem; + widget_contents.set(message.id, widget_elem); set_widget_in_message(row, widget_elem); // Replay any events that already happened. (This is common @@ -70,16 +70,16 @@ exports.activate = function (in_opts) { }; exports.set_widgets_for_list = function () { - _.each(widget_contents, function (widget_elem, idx) { + for (const [idx, widget_elem] of widget_contents) { if (current_msg_list.get(idx) !== undefined) { const row = current_msg_list.get_row(idx); set_widget_in_message(row, widget_elem); } - }); + } }; exports.handle_event = function (widget_event) { - const widget_elem = widget_contents[widget_event.message_id]; + const widget_elem = widget_contents.get(widget_event.message_id); if (!widget_elem) { // It is common for submessage events to arrive on