diff --git a/src/view.ts b/src/view.ts index 36a4237..6992406 100644 --- a/src/view.ts +++ b/src/view.ts @@ -14,17 +14,27 @@ let activeContainerIndex = -1; export const getViewContent = () => containers[activeContainerIndex]?.content; +/** + * clears current view so it is empty and ready to be re-used. + * only clears the current view, not all views + */ export const clearView = () => { - // TODO: this is clears the current view, but it should probably do this for all views const domMap = containers[activeContainerIndex]?.dom; Object.keys(domMap).forEach(eventId => delete domMap[eventId]); getViewContent().replaceChildren(); }; +/** + * get elmenet stored in internal DOMMap of the current view + * alternative to internal map in view.dom, is to use id="" attribute, however same event could be shown in different views so event.id is not unique. + */ export const getViewElem = (id: string) => { return containers[activeContainerIndex]?.dom[id]; }; +/** + * store element in internal view.dom map using id as key + */ export const setViewElem = (id: string, node: HTMLElement) => { const container = containers[activeContainerIndex]; if (container) { @@ -54,6 +64,11 @@ type GetViewOptions = () => ViewTemplateOptions; */ export const getViewOptions: GetViewOptions = () => containers[activeContainerIndex]?.options || {type: 'feed'}; +/** + * changes the current view and transitions to the view specified by route + * example: + * view('/npub0293ji3gojaed32r4r412', {type: 'feed}) + */ export const view = ( route: string, options: ViewTemplateOptions,