Skip to content

Commit

Permalink
Don't rely on actual typenames
Browse files Browse the repository at this point in the history
  • Loading branch information
ralismark committed May 12, 2024
1 parent 8833712 commit b59f14f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function WidgetCard(props: { widget: Widget, ctl: WidgetControl, focusHook: any
}, [elem, props.focusHook])

return <article
className={"WidgetCard " + props.widget.constructor.name}
className={"WidgetCard " + props.widget.typename()}
ref={elem}
>
<h1>
Expand Down
6 changes: 5 additions & 1 deletion src/components/CalendarWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "./CalendarWidget.css"
import { useState } from "react"
import { FacadeExtern } from "../backend"
import { useExtern, useExternOr } from "../extern"
import "./CalendarWidget.css"
import { WidgetControl, Widget } from "./Widget"
import { dateRange, shortdate, today } from "../util/calendar"
import { FileWidget } from "./FileWidget"
Expand Down Expand Up @@ -76,4 +76,8 @@ export class CalendarWidget implements Widget {
</>
]
}

typename(): string {
return "CalendarWidget"
}
}
4 changes: 4 additions & 0 deletions src/components/ConfigWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ export class ConfigWidget implements Widget {
</>,
]
}

typename(): string {
return "ConfigWidget"
}
}
4 changes: 4 additions & 0 deletions src/components/FileWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ export class FileWidget implements Widget {
</>,
]
}

typename(): string {
return "FileWidget"
}
}
3 changes: 2 additions & 1 deletion src/components/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ export interface WidgetControl extends SiteControl {
}

export interface Widget {
typename(): string
show(ctl: WidgetControl): [JSX.Element, JSX.Element]
}

// Get a string that fully represents the contents of the widget
export function widgetToString(w: Widget) {
return w.constructor.name + ":" + JSON.stringify(w)
return w.typename() + ":" + JSON.stringify(w)
}

0 comments on commit b59f14f

Please sign in to comment.