From 9a7bb3db01fe2e99ccc12285c63323bc67c278e8 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Mon, 20 Jun 2022 19:50:32 +1000 Subject: Increase type-consistency via server-classes and client-types --- src/lib.ts | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/lib.ts') diff --git a/src/lib.ts b/src/lib.ts index 67ac4c3..a6c8df1 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1,7 +1,43 @@ /* - * Types + * Types/classes */ +// Used for tree-of-life representation +// Maps tree-of-life node names to node objects +export type TolMap = Map; +// Represents a tree-of-life node +export class TolNode { + otolId: string | null; + children: string[]; + parent: string | null; + tips: number; + pSupport: boolean; + commonName: null | string; + imgName: null | string | [string, string] | [null, string] | [string, null]; + constructor(children: string[] = [], parent = null, tips = 0, pSupport = false){ + this.otolId = null; + this.children = children; + this.parent = parent; + this.tips = tips; + this.pSupport = pSupport; + this.commonName = null; + this.imgName = null; + } +} +// Used for server search-responses +export type SearchSugg = {name: string, canonicalName: string | null}; + // Represents a search-string suggestion +export type SearchSuggResponse = {suggs: SearchSugg[], hasMore: boolean}; + // Holds search suggestions and an indication of if there was more +// Used for server info-responses +export type DescInfo = {text: string, wikiId: number, fromRedirect: boolean, fromDbp: boolean}; +export type ImgInfo = {id: number, src: string, url: string, license: string, artist: string, credit: string} +export type TileInfoResponse = { + tolNode: null | TolNode, + descData: null | DescInfo | [DescInfo, DescInfo], + imgData: null | ImgInfo | [ImgInfo, ImgInfo], +}; + // Used by auto-mode and tutorial export type Action = 'expand' | 'collapse' | 'expandToView' | 'unhideAncestor' | -- cgit v1.2.3