packages feed

miso-examples 1.8.0.0 → 1.8.1.0

raw patch · 5 files changed

+100/−9 lines, 5 filesnew-component:exe:simple

Files

miso-examples.cabal view
@@ -1,5 +1,5 @@ name:                miso-examples-version:             1.8.0.0+version:             1.8.1.0 category:            Web, Miso, Data Structures author:              David M. Johnson <djohnson.m@gmail.com> maintainer:          David M. Johnson <djohnson.m@gmail.com>@@ -29,6 +29,37 @@     False   description:     Cross compile to iOS++executable simple+  main-is:+    Main.hs+  if !impl(ghcjs) && !flag(jsaddle)+    buildable: False+  else+    ghcjs-options:+      -dedupe+    cpp-options:+      -DGHCJS_BROWSER+    hs-source-dirs:+      simple+    build-depends:+      aeson,+      base < 5,+      containers,+      miso,+      transformers+    default-language:+      Haskell2010+    if flag(ios)+      cpp-options:+        -DIOS+      ghc-options:+        -threaded+      build-depends:+        jsaddle-wkwebview+    else+      build-depends:+        jsaddle-warp  executable todo-mvc   main-is:
+ simple/Main.hs view
@@ -0,0 +1,66 @@+-- | Haskell language pragma+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE CPP #-}++-- | Haskell module declaration+module Main where++-- | Miso framework import+import Miso+import Miso.String++import Control.Monad.IO.Class++#ifdef IOS+import Language.Javascript.JSaddle.WKWebView as JSaddle++runApp :: JSM () -> IO ()+runApp = JSaddle.run+#else+import Language.Javascript.JSaddle.Warp as JSaddle++runApp :: JSM () -> IO ()+runApp = JSaddle.run 8080+#endif++-- | Type synonym for an application model+type Model = Int++-- | Sum type for application events+data Action+  = AddOne+  | SubtractOne+  | NoOp+  | SayHelloWorld+  deriving (Show, Eq)++-- | Entry point for a miso application+main :: IO ()+main = runApp $ miso $ \_ -> App {..}+  where+    initialAction = SayHelloWorld -- initial action to be executed on application load+    model  = 0                    -- initial model+    update = updateModel          -- update function+    view   = viewModel            -- view function+    events = defaultEvents        -- default delegated events+    subs   = []                   -- empty subscription list+    mountPoint = Nothing          -- mount point for application (Nothing defaults to 'body')+    logLevel = Off                -- Used to copy DOM into VDOM, applies only to `miso` function++-- | Updates model, optionally introduces side effects+updateModel :: Action -> Model -> Effect Action Model+updateModel AddOne m = noEff (m + 1)+updateModel SubtractOne m = noEff (m - 1)+updateModel NoOp m = noEff m+updateModel SayHelloWorld m = m <# do+  liftIO (putStrLn "Hello World") >> pure NoOp++-- | Constructs a virtual DOM from a model+viewModel :: Model -> View Action+viewModel x = div_ [] [+   button_ [ onClick AddOne ] [ text "+" ]+ , text (ms x)+ , button_ [ onClick SubtractOne ] [ text "-" ]+ , rawHtml "<div><p>hey expandable!</div></p>"+ ]
svg/Main.hs view
@@ -34,8 +34,6 @@ updateModel :: Action -> Model -> Effect Action Model updateModel (HandleTouch (TouchEvent touch)) model =   model <# do-    putStrLn "Touch did move"-    print touch     return $ HandleMouse $ trunc . page $ touch updateModel (HandleMouse newCoords) model =   noEff model { mouseCoords = newCoords }
svg/Touch.hs view
@@ -9,7 +9,7 @@  data Touch = Touch   { identifier :: Int-  , screen :: (Int, Int)+  , screen :: (Double, Double)   , client :: (Double, Double)   , page :: (Double, Double)   } deriving (Eq, Show)
todo-mvc/Main.hs view
@@ -168,7 +168,6 @@ viewModel m@Model{..} =  div_     [ class_ "todomvc-wrapper"-    , style_  $ M.singleton "visibility" "hidden"     ]     [ section_         [ class_ "todoapp" ]@@ -177,10 +176,6 @@         , viewControls m visibility entries         ]     , infoFooter-    , link_-        [ rel_ "stylesheet"-        , href_ "https://d33wubrfki0l68.cloudfront.net/css/d0175a264698385259b5f1638f2a39134ee445a0/style.css"-        ]     ]  viewEntries :: MisoString -> [ Entry ] -> View Msg@@ -193,6 +188,7 @@         [ class_ "toggle-all"         , type_ "checkbox"         , name_ "toggle"+        , id_ "toggle-all"         , checked_ allCompleted         , onClick $ CheckAll (not allCompleted)         ]