Hello folks,
I’ve been very impressed by the samples shared here, so I thought I’d contribute one of my own. It’s yet another COVID-19 7 day incidence widget: I don’t purport to take credit for the basic code, as that was cribbed from a widget shared on Twitter (if anybody knows the original author: please get in touch, so I can credit them). The reason I still share it here is that I improved it by implementing a few practices and patterns others might find useful in widget development. Among them are:
- Adaptive support for different widget sizes, dark mode and accessibilty text settings.
- Robust handling of messy parameters and variance in returned data.
- Fully internationalised for German and English, using my i18n module.
- Uses system display formats for numbers and dates.
- Caching of data for offline refresh cycles (with indicator of stale data).
- Data handling decoupled from widget building for adaptability.
- Easy in-script configuration through an object.
- Optional debug logging.
The localisation and decoupled structure mean that, although the widget currently pulls German data from (obviously) a German service, it can easily be adapted to other data sources by modifying two short functions.
As the code is a bit long, I’ll just point you to the Github repository.