Giter Club home page Giter Club logo

miso-jswidget-example's Introduction

Miso JS widget example

Elegantly embedding arbitrary Javascript widgets in Miso.

Note:

Currently running off a fork of Miso, until the methods in this example have been fleshed out. Follow its progress here: dmjio/miso#362

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 Model is 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, viewModel function and is the parent of a Flatpickr component. Main.hs is not aware of any Javascript shenanigans.

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 Action with which the parent can modify the state of the widget, in our case just set the date;
  • destroy the widget and cleans 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-build

Then open result/index.html to run the example.

miso-jswidget-example's People

Contributors

fptje avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.