Safe Haskell | None |
---|---|
Language | Haskell2010 |
Usually, it makes the most sense to run a Myxine application using the
Page
abstraction in the main module. However, this reactive
model-view-controller approach may not be appropriate for all needs. The
functions below are a one-to-one mapping to the API of the Myxine server.
Like the Myxine server API itself, this interface has a small surface area. You
can send a new page Update
using sendUpdate
, you can loop over all page
events using withEvents
, and you can evaluate raw JavaScript using
evaluateJs
.
Synopsis
- data PageLocation
- pagePort :: PagePort -> PageLocation
- data PagePort
- pagePath :: PagePath -> PageLocation
- data PagePath
- data Update
- data PageContent
- pageBody :: Text -> PageContent
- pageTitle :: Text -> PageContent
- sendUpdate :: PageLocation -> Update -> IO ()
- withEvents :: PageLocation -> Maybe [Some EventType] -> (forall d. EventType d -> d -> [Target] -> IO ()) -> IO ()
- data JavaScript
- evaluateJs :: FromJSON a => PageLocation -> Maybe Int -> JavaScript -> IO (Either String a)
- data EventParseException
Page locations on localhost
data PageLocation Source #
The options for connecting to the Myxine server. This is an opaque
Monoid
: set options by combining pagePort
and/or pagePath
using their
Semigroup
instance.
Instances
pagePort :: PagePort -> PageLocation Source #
Set the port to a non-default port. This is only necessary when Myxine is running on a non-default port also.
A local port at which the server is expected to be running. Create one
using an integer literal or fromInteger
.
pagePath :: PagePath -> PageLocation Source #
Set the path to something other than the default of /
.
A path at "localhost/..." at which to perform some action. Create one using
a string literal or fromString
.
Sending updates to pages
A full page update as ready-to-send to the Myxine server.
Dynamic | A dynamic page which can be updated live |
Static | A static file which is hosted precisely as specified |
|
data PageContent Source #
The view of a page, as rendered in the browser. Create page content with
pageBody
and pageTitle
, and combine content using the Semigroup
instance.
Note: The Semigroup
instance for PageContent
takes the last specified
pageTitle
(if any), and concatenates in order each specified pageBody
.
Instances
pageBody :: Text -> PageContent Source #
Create a rendered PageContent
with an empty title
and the specified
text as its body
.
pageTitle :: Text -> PageContent Source #
Create a rendered PageContent
with an empty body
and the specified
text as its title
.
:: PageLocation | The location of the page to update |
-> Update | The new content of the page to display |
-> IO () |
Looping over typed events
:: PageLocation | The location of the page to listen for events from |
-> Maybe [Some EventType] | The list of events for which to listen |
-> (forall d. EventType d -> d -> [Target] -> IO ()) | The action to perform when each event happens |
-> IO () |
Given a page location and list of events, make a request to Myxine for the
event stream at that location and run the provided callback for each typed
event in the stream. If no list of events is specified (Nothing
), every
event will be listened for. If the specific list of no events (Just []
) is
specified, this function will sleep forever.
This blocks until the stream is closed by the server, or an exception is
encountered. This throws EventParseException
if the server sends an
unparseable event (this shouldn't happen in normal operation), and
HttpException
if the underlying connection has an issue.
Evaluating raw JavaScript in the context of a page
data JavaScript Source #
A piece of raw JavaScript to evaluate: either an expression or a block of
statements. Expressions need not terminate with a return
statement but
cannot span multiple lines; block need to have an explicit return
, but can
contain multiple statements and lines.
JsExpression Text | A JavaScript expression |
JsBlock Text | A block of JavaScript statements |
Instances
Eq JavaScript Source # | |
Defined in Myxine.Direct (==) :: JavaScript -> JavaScript -> Bool # (/=) :: JavaScript -> JavaScript -> Bool # | |
Ord JavaScript Source # | |
Defined in Myxine.Direct compare :: JavaScript -> JavaScript -> Ordering # (<) :: JavaScript -> JavaScript -> Bool # (<=) :: JavaScript -> JavaScript -> Bool # (>) :: JavaScript -> JavaScript -> Bool # (>=) :: JavaScript -> JavaScript -> Bool # max :: JavaScript -> JavaScript -> JavaScript # min :: JavaScript -> JavaScript -> JavaScript # | |
Show JavaScript Source # | |
Defined in Myxine.Direct showsPrec :: Int -> JavaScript -> ShowS # show :: JavaScript -> String # showList :: [JavaScript] -> ShowS # |
:: FromJSON a | |
=> PageLocation | The location of the page in which to evaluate the JavaScript |
-> Maybe Int | An optional override for the default timeout of 1000 milliseconds |
-> JavaScript | The JavaScript to evaluate: either a |
-> IO (Either String a) |
Evaluate some raw JavaScript in the context of a given page
Returns either a deserialized Haskell type, or a human-readable string describing any error that occurred. Possible errors include:
- Any exception in the given JavaScript
- Absence of any browser window currently viewing the page (since there's no way to evaluate JavaScript without a JavaScript engine)
- Evaluation timeout (default is 1000 milliseconds, but can be overridden in the timeout parameter to this function
- Invalid JSON response for the result type inferred (use
Value
if you don't know what shape of data you're waiting to receive).
Further caveats:
- JavaScript
undefined
is translated tonull
in the results JsBlock
inputs which don't explicitly return a value result innull
- Return types are limited to those which can be serialized via
@JSON.stringify@,
which does not work for cyclic objects (like
window
,document
, and all DOM nodes), and may fail to serialize some properties for other non-scalar values. If you want to return a non-scalar value like a list or dictionary, construct it explicitly yourself by copying from the fields of the object you're interested in.
Exceptions
data EventParseException Source #
If the response from the server fails to parse, this exception is thrown. This should never happen in ordinary circumstances; if it does, your version of the client library may mismatch the version of the Myxine server you are running, or there may be a bug in the Myxine server or this library.
If you encounter this exception in the wild, please file a bug report at https://github.com/GaloisInc/myxine/issues/new. Thanks!
TargetParseException String | The target path failed to parse |
UnknownEventTypeException ByteString | The event type failed to parse |
EventDataParseException ByteString String ByteString | The properties associated with the event type failed to parse |
Instances
Eq EventParseException Source # | |
Defined in Myxine.Direct (==) :: EventParseException -> EventParseException -> Bool # (/=) :: EventParseException -> EventParseException -> Bool # | |
Ord EventParseException Source # | |
Defined in Myxine.Direct compare :: EventParseException -> EventParseException -> Ordering # (<) :: EventParseException -> EventParseException -> Bool # (<=) :: EventParseException -> EventParseException -> Bool # (>) :: EventParseException -> EventParseException -> Bool # (>=) :: EventParseException -> EventParseException -> Bool # max :: EventParseException -> EventParseException -> EventParseException # min :: EventParseException -> EventParseException -> EventParseException # | |
Show EventParseException Source # | |
Defined in Myxine.Direct showsPrec :: Int -> EventParseException -> ShowS # show :: EventParseException -> String # showList :: [EventParseException] -> ShowS # | |
Exception EventParseException Source # | |
Defined in Myxine.Direct |