client-side half of a typed AJAX communication channel.
To use this library, you could start by defining a type in a file that can be shared between the Haskell Server and Fay client. For example:
data Command = SendGuess Guess (ResponseType (Maybe Row)) | FetchBoard (ResponseType (Maybe Board)) deriving (Read, Show, Data, Typeable) instance Foreign Command
ResponseType argument specifies what type each command should
return. Using GADTs would be cleaner, but Fay does not support GADTs
To execute a remote function we use the
call /ajax FetchBoard $ mboard -> ...
block until the
call returns a value, so we perform the AJAX request
asynchronously. The third argument to
call is the callback function
to run when the response is received.
|-> (ResponseType res -> cmd)|
AJAX command to send to server
|-> (res -> Fay ())|
callback function to handle response
|-> Fay ()|
Asynchronously call a command
Note: if the server returns 404 or some other non-success exit code, the callback function will never be run.
This function is just a wrapper around
ajaxCommand which uses the
'ResponseType res' phantom-typed parameter for added type safety.