Safe Haskell | None |
---|---|
Language | Haskell98 |
Type-safe client-server communication framework for Haste.
In addition to the Haste.App extras, this module exports the same API as Haste, modified slightly to work better with the automatic program slicing Haste.App provides. This means that you should import either this module *or* Haste, but *not* both.
- class Monad m => MonadIO m where
- class Remotable a
- data App a
- data Server a
- data Remote a
- data Done
- type Sessions = Set SessionID
- type SessionID = Word64
- liftServerIO :: IO a -> App (Server a)
- forkServerIO :: Server () -> App (Server ThreadId)
- remote :: Remotable a => a -> App (Remote a)
- runApp :: AppCfg -> App Done -> IO ()
- (<.>) :: Binary a => Remote (a -> b) -> a -> Remote b
- getSessionID :: Server SessionID
- getActiveSessions :: Server Sessions
- onSessionEnd :: (SessionID -> Server ()) -> App ()
- data AppCfg
- cfgHost :: AppCfg -> String
- cfgPort :: AppCfg -> Int
- mkConfig :: String -> Int -> AppCfg
- data Client a
- runClient :: Client () -> App Done
- onServer :: Binary a => Remote (Server a) -> Client a
- liftIO :: MonadIO m => forall a. IO a -> m a
- data JSString
- data JSAny
- type URL = String
- alert :: MonadIO m => String -> m ()
- prompt :: MonadIO m => String -> m String
- eval :: MonadIO m => JSString -> m JSString
- writeLog :: MonadIO m => String -> m ()
- catJSStr :: JSString -> [JSString] -> JSString
- fromJSStr :: JSString -> String
- newtype Elem = Elem JSAny
- class IsElem a where
- data Attribute
- data AttrName
- set :: (IsElem e, MonadIO m) => e -> [Attribute] -> m ()
- with :: (IsElem e, MonadIO m) => m e -> [Attribute] -> m e
- attribute :: AttrName -> JSString -> Attribute
- children :: [Elem] -> Attribute
- click :: (IsElem e, MonadIO m) => e -> m ()
- focus :: (IsElem e, MonadIO m) => e -> m ()
- blur :: (IsElem e, MonadIO m) => e -> m ()
- document :: Elem
- documentBody :: Elem
- deleteChild :: (IsElem parent, IsElem child, MonadIO m) => parent -> child -> m ()
- clearChildren :: (IsElem e, MonadIO m) => e -> m ()
- setChildren :: (IsElem parent, IsElem child, MonadIO m) => parent -> [child] -> m ()
- getChildren :: (IsElem e, MonadIO m) => e -> m [Elem]
- getLastChild :: (IsElem e, MonadIO m) => e -> m (Maybe Elem)
- getFirstChild :: (IsElem e, MonadIO m) => e -> m (Maybe Elem)
- getChildBefore :: (IsElem e, MonadIO m) => e -> m (Maybe Elem)
- insertChildBefore :: (IsElem parent, IsElem before, IsElem child, MonadIO m) => parent -> before -> child -> m ()
- appendChild :: (IsElem parent, IsElem child, MonadIO m) => parent -> child -> m ()
- removeChild :: (IsElem parent, IsElem child, MonadIO m) => child -> parent -> m ()
- addChild :: (IsElem parent, IsElem child, MonadIO m) => child -> parent -> m ()
- addChildBefore :: (IsElem parent, IsElem child, MonadIO m) => child -> parent -> child -> m ()
- class Random a where
- data Seed
- next :: Seed -> Seed
- mkSeed :: Int -> Seed
- newSeed :: MonadIO m => m Seed
- class JSType a where
- toJSString :: a -> JSString
- fromJSString :: JSString -> Maybe a
- class JSNum a where
- toNumber :: a -> Double
- fromNumber :: Double -> a
- toString :: JSType a => a -> String
- fromString :: JSType a => String -> Maybe a
- convert :: (JSNum a, JSNum b) => a -> b
- onHashChange :: MonadIO m => (String -> String -> IO ()) -> m ()
- onHashChange' :: MonadIO m => (JSString -> JSString -> IO ()) -> m ()
- setHash :: MonadIO m => String -> m ()
- getHash :: MonadIO m => m String
- setHash' :: MonadIO m => JSString -> m ()
- getHash' :: MonadIO m => m JSString
- module Haste.Binary
Documentation
class Monad m => MonadIO m where
Monads in which IO
computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO
monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
MonadIO IO | |
MonadIO Shell | |
MonadIO CIO | |
MonadIO Server | |
MonadIO Client | |
MonadIO m => MonadIO (ListT m) | |
MonadIO m => MonadIO (MaybeT m) | |
MonadIO m => MonadIO (IdentityT m) | |
(Error e, MonadIO m) => MonadIO (ErrorT e m) | |
(Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
(Monoid w, MonadIO m) => MonadIO (WriterT w m) |
An exportable function is of the type (Serialize a, ..., Serialize result) => a -> ... -> IO result
serializify
Application monad; allows for exporting functions, limited liftIO, forkIO and launching the client.
Server monad for Haste.App. Allows redeeming remote values, lifting IO actions, and not much more.
liftServerIO :: IO a -> App (Server a) Source
Lift an IO action into the Server monad, the result of which can only be used server-side.
forkServerIO :: Server () -> App (Server ThreadId) Source
Fork off a Server computation not bound an API call. This may be useful for any tasks that will keep running for as long as the server is running.
Calling getSessionID
inside this computation will return 0, which will
never be generated for an actual session. getActiveSessions
works as
expected.
remote :: Remotable a => a -> App (Remote a) Source
Make a function available to the client as an API call.
runApp :: AppCfg -> App Done -> IO () Source
Run a Haste.App application. runApp never returns before the program terminates.
Note that runApp
is single-entry, and that its argument must not
depend on any external IO. It is *strongly* recommended that the main
function of any Haste.App program *only* consists of a single call to
runApp
.
(<.>) :: Binary a => Remote (a -> b) -> a -> Remote b Source
Apply an exported function to an argument. TODO: look into making this Applicative.
getSessionID :: Server SessionID Source
Returns the ID of the current session.
getActiveSessions :: Server Sessions Source
Return all currently active sessions.
onSessionEnd :: (SessionID -> Server ()) -> App () Source
Register a handler to be run whenever a session terminates. Several handlers can be registered at the same time; they will be run in the order they were registered.
mkConfig :: String -> Int -> AppCfg Source
Create a default configuration from a host name and a port number.
A client-side computation. See it as Haste.App's version of the IO monad.
runClient :: Client () -> App Done Source
Launch a client from a Server computation. runClient never returns before the program terminates.
onServer :: Binary a => Remote (Server a) -> Client a Source
Perform a server-side computation, blocking the client thread until said computation returns.
JSStrings are represented as normal strings server-side; should probably be changed to ByteString or Text.
catJSStr :: JSString -> [JSString] -> JSString Source
Concatenate a series of JSStrings using the specified separator.
The class of types backed by DOM elements.
A key/value pair representing the value of an attribute. May represent a property, an HTML attribute, a style attribute or a list of child elements.
The name of an attribute. May be either a common property, an HTML attribute or a style attribute.
set :: (IsElem e, MonadIO m) => e -> [Attribute] -> m () Source
Set a number of Attribute
s on an element.
The DOM node corresponding to document.body.
deleteChild :: (IsElem parent, IsElem child, MonadIO m) => parent -> child -> m () Source
Remove the second element from the first's children.
clearChildren :: (IsElem e, MonadIO m) => e -> m () Source
Remove all children from the given element.
setChildren :: (IsElem parent, IsElem child, MonadIO m) => parent -> [child] -> m () Source
Clear the given element's list of children, and append all given children to it.
getChildren :: (IsElem e, MonadIO m) => e -> m [Elem] Source
Get a list of all children belonging to a certain element.
getLastChild :: (IsElem e, MonadIO m) => e -> m (Maybe Elem) Source
Get the last of an element's children.
getFirstChild :: (IsElem e, MonadIO m) => e -> m (Maybe Elem) Source
Get the first of an element's children.
getChildBefore :: (IsElem e, MonadIO m) => e -> m (Maybe Elem) Source
Get the sibling before the given one, if any.
insertChildBefore :: (IsElem parent, IsElem before, IsElem child, MonadIO m) => parent -> before -> child -> m () Source
Insert an element into a container, before another element.
For instance:
insertChildBefore theContainer olderChild childToAdd
appendChild :: (IsElem parent, IsElem child, MonadIO m) => parent -> child -> m () Source
Append the first element as a child of the second element.
removeChild :: (IsElem parent, IsElem child, MonadIO m) => child -> parent -> m () Source
Deprecated: Use deleteChild instead
DEPRECATED: use deleteChild
instead!
addChild :: (IsElem parent, IsElem child, MonadIO m) => child -> parent -> m () Source
Deprecated: Use appendChild instead
DEPRECATED: use appendChild
instead!
addChildBefore :: (IsElem parent, IsElem child, MonadIO m) => child -> parent -> child -> m () Source
Deprecated: Use insertChildBefore instead
DEPRECATED: use insertChildBefore
instead!
Any type which can be converted to/from a JSString
.
toJSString :: a -> JSString Source
fromJSString :: JSString -> Maybe a Source
(Almost) all numeric types can be efficiently converted to and from Double, which is the internal representation for most of them.
fromString :: JSType a => String -> Maybe a Source
onHashChange :: MonadIO m => (String -> String -> IO ()) -> m () Source
Register a callback to be run whenever the URL hash changes. The two arguments of the callback are the new and old hash respectively.
onHashChange' :: MonadIO m => (JSString -> JSString -> IO ()) -> m () Source
JSString version of onHashChange
.
setHash' :: MonadIO m => JSString -> m () Source
Set the hash part of the current URL - JSString version.
module Haste.Binary