mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 15:33:30 +00:00
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.
This commit is contained in:
committed by
Steve Howell
parent
96f466f635
commit
2cfead7601
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user