yesod-autoreload-0.0.0.0: Auto-reload a yesod app during development
Safe HaskellNone
LanguageHaskell2010

Yesod.AutoReload

Description

This module contains helper functions to help you implement auto-reloading in your yesod site.

If this is implemented correctly, you should be able to work on your application and see the browser automatically reload when you save.

To achieve this, your site will need to have a route that serves a websocket connection. You can use the helper functions in this library to implement that route. You will then add a little piece of javascript to the page you want to have reload. The autoReloadWidgetFor function can help you add that piece of javascript.

The browser will then make a websocket connection to the websocket route and reload (semi-intelligently) as soon as the connection is closed.

Synopsis

The websocket route

getAutoReloadR :: (MonadHandler m, MonadUnliftIO m) => m () Source #

A helper function to implement the websocket route that autoReloadWidgetFor will call.

This function is like getAutoReloadRWith except it takes no argument and just waits forever.

You can use this function to reload whenever the server restarts. This can work nicely with stack build --file-watch.

getAutoReloadRWith :: (MonadHandler m, MonadUnliftIO m) => WebSocketsT m () -> m () Source #

A helper function to implement the websocket route that autoReloadWidgetFor will call.

The argument is a function that will block until the page is supposed to be reloaded. When watching a directory for example, you will want to block until a file has changed. You can use an empty 'MVar ()', a callback that fills it, and takeMVar to implement such a thing.

The bit of javascript

autoReloadWidgetFor :: Route site -> WidgetFor site () Source #

A widget that takes care of reloading the page whenever the websocket connection to the given route is closed.

See getAutoReloadRWith about implementing such a websocket route.