pm_list_dom: Convert module to TypeScript.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-02 15:57:17 -07:00 committed by Tim Abbott
parent 961c7185ab
commit e459b83c06
3 changed files with 27 additions and 10 deletions

View File

@ -142,7 +142,7 @@ EXEMPT_FILES = make_set(
"web/src/playground_links_popover.js", "web/src/playground_links_popover.js",
"web/src/plotly.js.d.ts", "web/src/plotly.js.d.ts",
"web/src/pm_list.js", "web/src/pm_list.js",
"web/src/pm_list_dom.js", "web/src/pm_list_dom.ts",
"web/src/poll_widget.js", "web/src/poll_widget.js",
"web/src/popover_menus.js", "web/src/popover_menus.js",
"web/src/popover_menus_data.js", "web/src/popover_menus_data.js",

View File

@ -5,10 +5,19 @@ import render_pm_list_item from "../templates/pm_list_item.hbs";
import * as vdom from "./vdom"; import * as vdom from "./vdom";
export function keyed_pm_li(conversation) { // TODO/typescript: Move this to pm_list_data
const render = () => render_pm_list_item(conversation); type PMListConversation = {
user_ids_string: string;
};
const eq = (other) => _.isEqual(conversation, other.conversation); type PMNode = vdom.Node & {
conversation: PMListConversation;
};
export function keyed_pm_li(conversation: PMListConversation): PMNode {
const render = (): string => render_pm_list_item(conversation);
const eq = (other: PMNode): boolean => _.isEqual(conversation, other.conversation);
const key = conversation.user_ids_string; const key = conversation.user_ids_string;
@ -20,12 +29,20 @@ export function keyed_pm_li(conversation) {
}; };
} }
export function more_private_conversations_li(more_conversations_unread_count) { type MorePrivateConversationsNode = vdom.Node & {
const render = () => render_more_private_conversations({more_conversations_unread_count}); more_items: boolean;
more_conversations_unread_count: number;
};
export function more_private_conversations_li(
more_conversations_unread_count: number,
): MorePrivateConversationsNode {
const render = (): string =>
render_more_private_conversations({more_conversations_unread_count});
// Used in vdom.js to check if an element has changed and needs to // Used in vdom.js to check if an element has changed and needs to
// be updated in the DOM. // be updated in the DOM.
const eq = (other) => const eq = (other: MorePrivateConversationsNode): boolean =>
other.more_items && other.more_items &&
more_conversations_unread_count === other.more_conversations_unread_count; more_conversations_unread_count === other.more_conversations_unread_count;
@ -41,8 +58,8 @@ export function more_private_conversations_li(more_conversations_unread_count) {
}; };
} }
export function pm_ul(nodes) { export function pm_ul(nodes: vdom.Node[]): vdom.Tag {
const attrs = [ const attrs: [string, string][] = [
["class", "pm-list"], ["class", "pm-list"],
["data-name", "private"], ["data-name", "private"],
]; ];

View File

@ -151,7 +151,7 @@ export function update(
like `attrs` for attributes. like `attrs` for attributes.
For examples of creating vdom objects, look at For examples of creating vdom objects, look at
`pm_list_dom.js`. `pm_list_dom.ts`.
*/ */
function do_full_update(): void { function do_full_update(): void {
const rendered_dom = render_tag(new_dom); const rendered_dom = render_tag(new_dom);