miso 0.1.3.0 → 0.1.4.0
raw patch · 6 files changed
+112/−10 lines, 6 filesnew-component:exe:websocketPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +10/−7
- examples/todo-mvc/index.html +1/−1
- examples/websocket/Main.hs +72/−0
- examples/websocket/index.html +10/−0
- ghcjs-src/Miso/Html/Internal.hs +1/−1
- miso.cabal +18/−1
README.md view
@@ -4,7 +4,7 @@ <img width=10% src="https://emojipedia-us.s3.amazonaws.com/thumbs/240/apple/96/steaming-bowl_1f35c.png"> </a> <p align="center">A <i>tasty</i> <a href="https://www.haskell.org/"><strong>Haskell</strong></a> front-end framework</p>-</p> +</p> <p align="center"> <a href="https://haskell-miso-slack.herokuapp.com">@@ -34,19 +34,22 @@ ## Examples - TodoMVC- - [Link](https://d3u8rq3uy5wnb9.cloudfront.net/)+ - [Link](https://todo-mvc.haskell-miso.org/) - [Source](https://github.com/dmjio/miso/blob/master/examples/todo-mvc/Main.hs) - Mario- - [Link](https://dfhxhtlu1tq0x.cloudfront.net/)+ - [Link](https://mario.haskell-miso.org/) - [Source](https://github.com/dmjio/miso/blob/master/examples/mario/Main.hs)+ - Websocket+ - [Link](https://websocket.haskell-miso.org/)+ - [Source](https://github.com/dmjio/miso/blob/master/examples/websocket/Main.hs) - SVG- - [Link](https://d2dwfl7f3j7of0.cloudfront.net/)+ - [Link](https://svg.haskell-miso.org/) - Simple- - [Link](https://dco9lhtzw9c6i.cloudfront.net)+ - [Link](https://simple.haskell-miso.org/) - [Source](https://github.com/dmjio/miso/blob/master/exe/Main.hs) -## Documentation- - [GHCJS](https://d10z4r8eai3cm9.cloudfront.net/)+## Haddocks+ - [GHCJS](https://haddocks.haskell-miso.org/) - [GHC](http://hackage.haskell.org/package/miso) ## Getting Started
examples/todo-mvc/index.html view
@@ -2,7 +2,7 @@ <html> <head> <meta charset="utf-8">- <link rel='stylesheet' href='http://d33wubrfki0l68.cloudfront.net/css/d0175a264698385259b5f1638f2a39134ee445a0/style.css'/>+ <link rel='stylesheet' href='https://d33wubrfki0l68.cloudfront.net/css/d0175a264698385259b5f1638f2a39134ee445a0/style.css'/> </head> <body> <script src='all.js'></script>
+ examples/websocket/Main.hs view
@@ -0,0 +1,72 @@+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE ExtendedDefaultRules #-}+module Main where++import Data.Aeson+import GHC.Generics+import Data.Bool+import qualified Data.Map as M++import Miso+import Miso.String (MisoString)+import qualified Miso.String as S++main :: IO ()+main = startApp App {..}+ where+ model = Model mempty mempty+ events = defaultEvents+ subs = [ websocketSub uri protocols HandleWebSocket ]+ update = updateModel+ view = appView+ uri = URL "wss://echo.websocket.org"+ protocols = Protocols [ ]++updateModel :: Action -> Model -> Effect Model Action+updateModel (HandleWebSocket (WebSocketMessage (Message m))) model+ = noEff model { received = m }+updateModel (SendMessage msg) model = model <# do send msg >> pure Id+updateModel (UpdateMessage m) model = noEff model { msg = Message m }+updateModel _ model = noEff model++instance ToJSON Message+instance FromJSON Message++newtype Message = Message MisoString+ deriving (Eq, Show, Generic, Monoid)++data Action+ = HandleWebSocket (WebSocket Message)+ | SendMessage Message+ | UpdateMessage MisoString+ | Id++data Model = Model {+ msg :: Message+ , received :: MisoString+ } deriving (Show, Eq)++appView :: Model -> View Action+appView Model{..} = div_ [ style_ $ M.fromList [("text-align", "center")] ] [+ h1_ [style_ $ M.fromList [("font-weight", "bold")] ] [ a_ [ href_ "https://github.com/dmjio/miso" ] [ text $ S.pack "Miso Websocket Example" ] ]+ , h3_ [] [ text $ S.pack "wss://echo.websocket.org" ]+ , input_ [ type_ "text"+ , onInput UpdateMessage+ , onEnter (SendMessage msg)+ ] []+ , button_ [ onClick (SendMessage msg)+ ] [ text (S.pack "Send to echo server") ]+ , div_ [ ] [ p_ [ ] [ text received | not . S.null $ received ] ]+ ]++onEnter :: Action -> Attribute Action+onEnter action = onKeyDown $ bool Id action . (== KeyCode 13)
+ examples/websocket/index.html view
@@ -0,0 +1,10 @@+<!DOCTYPE html>+<html>+ <head>+ <meta charset="utf-8">+ <link rel='stylesheet' href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.4.3/css/bulma.min.css"'/>+ </head>+ <body>+ <script src='all.js'></script>+ </body>+</html>
ghcjs-src/Miso/Html/Internal.hs view
@@ -195,7 +195,7 @@ -- | For defining delegated events with options ----- > let clickHandler = on defaultOptions "click" emptyDecoder $ \() -> Action+-- > let clickHandler = onWithOptions defaultOptions "click" emptyDecoder $ \() -> Action -- > in button_ [ clickHandler, class_ "add" ] [ text_ "+" ] -- onWithOptions
miso.cabal view
@@ -1,5 +1,5 @@ name: miso-version: 0.1.3.0+version: 0.1.4.0 category: Web, Miso, Data Structures license: BSD3 license-file: LICENSE@@ -17,6 +17,7 @@ extra-source-files: README.md examples/todo-mvc/index.html+ examples/websocket/index.html examples/mario/imgs/jump/right.gif examples/mario/imgs/jump/left.gif examples/mario/imgs/stand/right.gif@@ -45,8 +46,24 @@ hs-source-dirs: examples/todo-mvc build-depends:+ aeson, base < 5,+ containers,+ miso+ default-language:+ Haskell2010++executable websocket+ main-is:+ Main.hs+ if !impl(ghcjs) || !flag(examples)+ buildable: False+ else+ hs-source-dirs:+ examples/websocket+ build-depends: aeson,+ base < 5, containers, miso default-language: