mirror of
https://github.com/zulip/zulip.git
synced 2026-06-30 21:11:04 +08:00
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:
parent
b19a7a8b8a
commit
151d51acfa
@ -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> = {
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user