web-rep-0.5.0: representations of a web page

Safe HaskellNone
LanguageHaskell2010

Web.Page.Bridge

Description

A streaming bridge between a web page and haskell.

Synopsis

Documentation

bridgePage :: Page Source #

componentry to kick off a javascript-bridge enabled page

append :: Engine -> Text -> Text -> IO () Source #

append to a container and run any embedded scripts

replace :: Engine -> Text -> Text -> IO () Source #

replace a container and run any embedded scripts

bridge :: Engine -> Cont_ IO Value Source #

The javascript bridge continuation.

sendConcerns :: Engine -> Text -> Concerns Text -> IO () Source #

send css, js and html over the bridge

data Engine #

An Engine is a handle to a specific JavaScript engine

start :: (Engine -> IO ()) -> Application -> Application #

This accepts WebSocket requests, calls the callback with an Engine that can be used to access JavaScript.

type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived #

The WAI application.

Note that, since WAI 3.0, this type is structured in continuation passing style to allow for proper safe resource handling. This was handled in the past via other means (e.g., ResourceT). As a demonstration:

app :: Application
app req respond = bracket_
    (putStrLn "Allocating scarce resource")
    (putStrLn "Cleaning up")
    (respond $ responseLBS status200 [] "Hello World")

valueConsume :: s -> (Element -> s -> s) -> Cont IO (Committer IO (Either Text s)) -> Cont_ IO Value -> IO s Source #

consume an Element using a Committer and a Value continuation

sharedConsume :: (s -> (s, Either Text b)) -> s -> (Element -> s -> s) -> Cont IO (Committer IO (Either Text (s, Either Text b))) -> Cont_ IO Value -> IO s Source #

consume shared values using a step function, a continuation committer, and a Value continuation.

runList :: Monad m => SharedRep m a -> [Value] -> m [Either Text (HashMap Text Text, Either Text a)] Source #

process a list of Values

runOnEvent :: SharedRep IO a -> (Rep a -> StateT (Int, HashMap Text Text) IO ()) -> (Either Text (HashMap Text Text, Either Text a) -> IO ()) -> Cont_ IO Value -> IO (HashMap Text Text) Source #

run a SharedRep using an initial state, a step function that consumes the shared model, and a value continuation

midShared :: SharedRep IO a -> (Engine -> Rep a -> StateT (HashMap Text Text) IO ()) -> (Engine -> Either Text (HashMap Text Text, Either Text a) -> IO ()) -> Application -> Application Source #

create Wai Middleware for a SharedRepF providing an initialiser and action on events

refreshJsbJs :: PageJs Source #

Event hooks that may need to be reattached given dynamic content creation.

runScriptJs :: PageJs Source #

script injection js.

See https://ghinda.net/article/script-tags/ for why this might be needed.