meiersi / blaze-react

A blaze-html style ReactJS binding for Haskell using GHCJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parameterise the request type

asayers opened this issue · comments

type Transition state request = state -> (state, [request])
runApp :: App state action request -> (request -> IO action) -> IO ()

This will allow people to define reified APIs for their async IO with multiple implementations, eg.

-- | Read from and write to an arbitrary key-value store
module Blaze.React.Examples.Persistence
    ( PersistenceRequest(..)
    , PersistenceAction(..)
    ) where

type Key   = Text
type Value = Text
type Error = Text

data PersistenceRequest
    = Write Key Value
    | Read Key

data PersistenceAction
    = WriteSuccess Key
    | WriteError Error
    | ReadSuccess Key Value
    | ReadError Error
-- | Implement the Persistence API using HTML5 LocalStorage
module Blaze.React.Examples.Persistence.BrowserLocalStorage
    ( runPersistenceRequest
    ) where
-- | Implement the Persistence API using a table in a PostgreSQL database
module Blaze.React.Examples.Persistence.PostgreSQL
    ( runPersistenceRequest
    ) where

This would be a good step towards making Apps more portable. There's still the issue that we allow arbitrary IO inside event handlers.

Note that the event handler IO access is only there to allow reading the
native event object. We could newtype IO here together with native object
accessor functions to remove arbitrary IO. Even better is probably to
remove IO and use pure closures. It will require us to make event API as
complete as possible and restricts some apps. However the majority will
become executable server-side too, which is a good thing IMHO.
Am 16.12.2014 18:20 schrieb "Alex Sayers" notifications@github.com:

type Transition state request = state -> (state, [request])runApp :: App state action request -> (request -> IO action) -> IO ()

This will allow people to define reified APIs with multiple
interpretations, eg.

-- | Read from and write to an arbitrary key-value storemodule Blaze.React.Examples.Persistence
( PersistenceRequest(..)
, PersistenceAction(..)
) where
type Key = Texttype Value = Texttype Error = Text
data PersistenceRequest
= Write Key Value
| Read Key
data PersistenceAction
= WriteSuccess Key
| WriteError Error
| ReadSuccess Key Value
| ReadError Error

-- | Implement the Persistence API using HTML5 LocalStoragemodule Blaze.React.Examples.Persistence.BrowserLocalStorage
( runPersistenceRequest
) where

-- | Implement the Persistence API using a table in a PostgreSQL databasemodule Blaze.React.Examples.Persistence.PostgreSQL
( runPersistenceRequest
) where

This would be a good step towards making Apps more portable. There's
still the issue that we allow arbitrary IO inside event handlers.


Reply to this email directly or view it on GitHub
#9.

Done in branch feat-async-apis.