From 2cfead7601262be77b79bd9fca8d29ecacc53c57 Mon Sep 17 00:00:00 2001 From: Rohitt Vashishtha Date: Thu, 28 May 2020 23:13:59 +0530 Subject: [PATCH] list_render: Add validate_opts function. We do not shift much of the validation logic here just yet. This function has been declared at the top of the file to act as usage docs for the widget as well, in terms of what combinations of opts are valid and what are not. --- static/js/list_render.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/static/js/list_render.js b/static/js/list_render.js index 02a040c139..ef2a73a61a 100644 --- a/static/js/list_render.js +++ b/static/js/list_render.js @@ -4,6 +4,22 @@ const DEFAULTS = { instances: new Map(), }; + +// ---------------------------------------------------- +// This function describes (programatically) how to use +// the list_render widget. +// ---------------------------------------------------- + +exports.validate_opts = (opts) => { + if (opts.html_selector && typeof opts.html_selector !== 'function') { + // We have an html_selector, but it is not a function. + // This is a programming error. + blueslip.error('html_selector should be a function.'); + return false; + } + return true; +}; + exports.get_filtered_items = (value, list, opts) => { /* This is used by the main object (see `create`), @@ -110,6 +126,10 @@ exports.create = function ($container, list, opts) { return; } + if (!exports.validate_opts(opts)) { + return; + } + if (opts.name && DEFAULTS.instances.get(opts.name)) { // Clear event handlers for prior widget. const old_widget = DEFAULTS.instances.get(opts.name);