Miso JS widget example
Elegantly embedding arbitrary Javascript widgets in Miso.
Note:
Also currently incompatible with Miso's isomorphism feature.
Try it live!
https://fptje.github.io/miso-jswidget-example/
About
This example shows how to deeply integrate a javascript widget into your Miso app, such that:
- you can listen to custom events defined by the widget's library;
- the inevitable Javascript interop is encapsulated in a single component; and that
- this component can be re-used and placed anywhere in your application, following the components pattern;
- the state of your Miso
Modelis synced with the state of the widget, and the other way around.
This example embeds flatpickr, a date picker and calendar widget.
The example explained
The example consists of two Haskell files: Main.hs and Flatpickr.hs. Main.hs contains a pretty standard Miso app, with a Model, some Actions and a viewModel function. The main app embeds the flatpickr component defined in Flatpickr.hs, but also creates some buttons and some text.
Flatpickr.hs fully encapsulates the flatpickr widget. It takes care of the following:
- create the widget (using Javascript interop) when it should be visible, passing options given by its parent;
- create an onChange event listener, turning all events into actions that are sent to its parent;
- define an
Actionwith which the parent can modify the state of the widget, in our case just set the date; - destroy the widget and clean up any callbacks when the DOM element it was attached to disappears.
Comments in the code explain the details. Go check it out!
Building the example
This example is built using Nix.
Build by running the following command:
nix-buildThen open result/index.html to run the example.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
