input_pill: Remove over defensive if checks for create function.

We should remove this overly defensive code and remove the `undefined`
type from the return type of this function to avoid handling unexpected
`undefined` values in the downstream code.
This commit is contained in:
Lalit 2023-10-27 21:59:03 +05:30 committed by Tim Abbott
parent b19a7a8b8a
commit 151d51acfa
2 changed files with 9 additions and 34 deletions

View File

@ -75,22 +75,7 @@ export type InputPillContainer<T> = {
_get_pills_for_testing: () => InputPill<T>[];
};
export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T> | undefined {
if (!opts.$container) {
blueslip.error("Pill needs container.");
return undefined;
}
if (!opts.create_item_from_text) {
blueslip.error("Pill needs create_item_from_text");
return undefined;
}
if (!opts.get_text_from_item) {
blueslip.error("Pill needs get_text_from_item");
return undefined;
}
export function create<T>(opts: InputPillCreateOptions<T>): InputPillContainer<T> {
// a stateful object of this `pill_container` instance.
// all unique instance information is stored in here.
const store: InputPillStore<T> = {

View File

@ -51,28 +51,18 @@ run_test("basics", ({mock_template}) => {
return html;
});
const config = {};
blueslip.expect("error", "Pill needs container.");
input_pill.create(config);
const $pill_input = $.create("pill_input");
const $container = $.create("container");
$container.set_find_results(".input", $pill_input);
blueslip.expect("error", "Pill needs create_item_from_text");
config.$container = $container;
input_pill.create(config);
blueslip.expect("error", "Pill needs get_text_from_item");
config.create_item_from_text = noop;
input_pill.create(config);
config.get_text_from_item = noop;
config.pill_config = {
show_user_status_emoji: true,
};
const widget = input_pill.create(config);
const widget = input_pill.create({
$container,
create_item_from_text: noop,
get_text_from_item: noop,
pill_config: {
show_user_status_emoji: true,
},
});
const status_emoji_info = {emoji_code: 5};
// type for a pill can be any string but it needs to be