Deadpan-DDP-0.3.0.1: Write clients for Meteor's DDP Protocol

Safe HaskellNone
LanguageHaskell2010

Web.DDP.Deadpan.DSL

Description

An EDSL designed to make writing deadpan applications easy!

This DSL is a simple decoration of some application specific functions arround an RWST monad instance.

TODO: Check that this is still correct...

  type deadpanapp a = Control.Monad.Rws.Rwst
                        network.websockets.connection
                        ()
                        callbackset
                        io
                        a

A core cabal of functions are exported from this module which are then put to use in web.ddp.deadpan to create an expressive dsl for creating ddp applications.

The main functions exported are...

TODO: Ensure these are up to date...

  • rundeadpan
  • sethandler
  • deletehandler
  • setdefaulthandler
  • senddata
  • sendmessage

these allow you to...

  • run a deadpan application with some initial set of callbacks
  • set new values for response handlers
  • delete existing response handlers
  • set a handler to act when no existing handler matches the incomming message
  • send an ejsonvalue to the server (low-level)
  • send messages to be interpreted as rpc calls

... respectively.

There is also a `control.lens.lens` collections provided into a single ejsonvalue.

This can be used to...

  • Retrieve any current collection data
  • Set collection data manually
  • Perform actions on collection data in callbacks

Synopsis

Documentation

type Lookup a = Map Text a Source

data AppState cb Source

Constructors

AppState 

Fields

_defaultCallback :: cb

The callback to run when no other callbacks match

_callbackSet :: Lookup cb

Callbacks to match against by message

_collections :: TVar EJsonValue

Shared data Expected to be an EJObject , _localState :: ls -- ^ Thread-Local state -- TODO: Currently disabled

defaultCallback :: forall cb. Lens' (AppState cb) cb Source

callbackSet :: forall cb. Lens' (AppState cb) (Lookup cb) Source

runDeadpan :: DeadpanApp a -> Connection -> AppState Callback -> IO (a, AppState Callback) Source

The order of these args match that of runRWST

sendData :: EJsonValue -> DeadpanApp () Source

A low-level function intended to be able to send any arbitrary data to the server. Given that all messages to the server are intended to fit the "message" format, You should probably use sendMessage instead. TODO: Decide if this should perform the request in a seperate thread...

sendMessage :: Text -> EJsonValue -> DeadpanApp () Source

Send a particular type of message (indicated by the key) to the server. This should be the primary means of [client -> server] communication by a client application.

fork :: DeadpanApp a -> DeadpanApp () Source

Provides a way to fork a background thread running the app provided TODO: Consider returning the thread-id

module Data.EJson

data Text :: *

A space efficient, packed, unboxed Unicode text type.

Instances

IsList Text 
Eq Text 
Data Text

This instance preserves data abstraction at the cost of inefficiency. We omit reflection services for the sake of data abstraction.

This instance was created by copying the updated behavior of Data.Set.Set and Data.Map.Map. If you feel a mistake has been made, please feel free to submit improvements.

The original discussion is archived here: could we get a Data instance for Data.Text.Text?

The followup discussion that changed the behavior of Set and Map is archived here: Proposal: Allow gunfold for Data.Map, ...

Ord Text 
Read Text 
Show Text 
IsString Text 
ToJSON Text 
FromJSON Text 
Chunk Text 
Monoid Text 
NFData Text 
Hashable Text 
Semigroup Text 
Ixed Text 
WebSocketsData Text 
Typeable * Text 
Convertible Text Text 
Convertible Text Text 
Strict Text Text 
Convertible Text [Char] 
Convertible [Char] Text 
ToJSON v => ToJSON (HashMap Text v) 
ToJSON v => ToJSON (Map Text v) 
FromJSON v => FromJSON (HashMap Text v) 
FromJSON v => FromJSON (Map Text v) 
type State Text = Buffer 
type ChunkElem Text = Char 
type Item Text = Char 
type Index Text = Int 
type IxValue Text = Char