miso 0.1.2.0 → 0.1.3.0
raw patch · 5 files changed
+56/−52 lines, 5 filesdep +BoundedChanPVP ok
version bump matches the API change (PVP)
Dependencies added: BoundedChan
API changes (from Hackage documentation)
Files
- README.md +32/−8
- examples/mario/Main.hs +13/−12
- ghcjs-src/Miso/Subscription/Keyboard.hs +2/−2
- miso.cabal +2/−1
- src/Miso/Concurrent.hs +7/−29
README.md view
@@ -1,12 +1,35 @@-:ramen: miso-======================-[](http://hackage.haskell.org/package/miso)-[](https://haskell.org)-[](https://github.com/dmjio/miso/blob/master/LICENSE)-[](https://www.irccloud.com/invite?channel=%23haskell-miso&hostname=irc.freenode.net&port=6697&ssl=1)-[](https://haskell-miso-slack.herokuapp.com)-[](https://hydra.dmj.io)+<h1 align="center">miso</h1>+<p align="center">+<a href="https://haskell-miso.org">+ <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 align="center">+ <a href="https://haskell-miso-slack.herokuapp.com">+ <img src="https://img.shields.io/badge/slack-miso-E01563.svg?style=flat-square" alt="Miso Slack">+ </a>+ <a href="http://hackage.haskell.org/package/miso">+ <img src="https://img.shields.io/hackage/v/miso.svg?style=flat-square" alt="Hackage">+ </a>+ <a href="https://haskell.org">+ <img src="https://img.shields.io/badge/language-Haskell-green.svg?style=flat-square" alt="Haskell">+ </a>+ <a href="https://img.shields.io/hackage-deps/v/miso.svg">+ <img src="https://img.shields.io/hackage-deps/v/miso.svg?style=flat-square" alt="Hackage">+ </a>+ <a href="https://github.com/dmjio/miso/blob/master/LICENSE">+ <img src="http://img.shields.io/badge/license-BSD3-brightgreen.svg?style=flat-square" alt="LICENSE">+ </a>+ <a href="https://hydra.dmj.io">+ <img src="https://img.shields.io/badge/build-Hydra-00BDFD.svg?style=flat-square" alt="Miso Hydra">+ </a>+ <a href="https://www.irccloud.com/invite?channel=%23haskell-miso&hostname=irc.freenode.net&port=6697&ssl=1">+ <img src="https://img.shields.io/badge/irc-%23haskell--miso-1e72ff.svg?style=flat-square" alt="IRC #haskell-miso">+ </a>+</p>+ **Miso** is a small "[isomorphic](http://nerds.airbnb.com/isomorphic-javascript-future-web-apps/)" [Haskell](https://www.haskell.org/) front-end framework featuring a virtual-dom, diffing / patching algorithm, event delegation, event batching, SVG, Server-sent events, Websockets, and an extensible Subscription-based subsystem. Inspired by [Elm](http://elm-lang.org/), [Redux](http://redux.js.org/) and [Bobril](http://github.com/bobris/bobril). `IO` and other effects (like `XHR`) can be introduced into the system via the `Effect` data type. Miso makes heavy use of the [GHCJS](https://github.com/ghcjs/ghcjs) FFI and therefore has minimal dependencies. ## Examples@@ -29,6 +52,7 @@ ## Getting Started ```haskell {-# LANGUAGE RecordWildCards #-}+ module Main where import Miso
examples/mario/Main.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE MultiWayIf #-}+{-# LANGUAGE BangPatterns #-} module Main where import Data.Function@@ -11,9 +12,9 @@ import Miso.String data Action- = GetArrows Arrows- | Time Double- | WindowCoords (Int,Int)+ = GetArrows !Arrows+ | Time !Double+ | WindowCoords !(Int,Int) foreign import javascript unsafe "$r = performance.now();" now :: IO Double@@ -32,15 +33,15 @@ ] data Model = Model- { x :: Double- , y :: Double- , vx :: Double- , vy :: Double- , dir :: Direction- , time :: Double- , delta :: Double- , arrows :: Arrows- , window :: (Int,Int)+ { x :: !Double+ , y :: !Double+ , vx :: !Double+ , vy :: !Double+ , dir :: !Direction+ , time :: !Double+ , delta :: !Double+ , arrows :: !Arrows+ , window :: !(Int,Int) } deriving (Show, Eq) data Direction
ghcjs-src/Miso/Subscription/Keyboard.hs view
@@ -36,8 +36,8 @@ -- 39 right arrow ( x = 1 ) -- 40 down arrow ( y = -1 ) data Arrows = Arrows {- arrowX :: Int- , arrowY :: Int+ arrowX :: !Int+ , arrowY :: !Int } deriving (Show, Eq) -- | Helper function to convert keys currently pressed to `Arrow`
miso.cabal view
@@ -1,5 +1,5 @@ name: miso-version: 0.1.2.0+version: 0.1.3.0 category: Web, Miso, Data Structures license: BSD3 license-file: LICENSE@@ -128,6 +128,7 @@ aeson, base < 5, bytestring,+ BoundedChan, containers, text if impl(ghcjs)
src/Miso/Concurrent.hs view
@@ -15,8 +15,8 @@ , newEventWriter ) where -import Control.Concurrent.MVar-import Control.Concurrent+import Control.Concurrent hiding (readChan)+import Control.Concurrent.BoundedChan import Control.Monad -- | Concurrent API for receiving events and writing to an event sink@@ -28,12 +28,12 @@ -- | Creates a new `EventWriter` newEventWriter :: IO () -> IO (EventWriter m) newEventWriter notify' = do- chan <- newChan+ chan <- newBoundedChan 50 pure $ EventWriter (write chan) (readChan chan) where write chan event = void . forkIO $ do- writeChan chan event+ void $ tryWriteChan chan $! event notify' -- | Concurrent API for `SkipChan` implementation@@ -45,30 +45,8 @@ -- | Create a new `Notify` newNotify :: IO Notify newNotify = do- skipChan <- newSkipChan+ mvar <- newMVar () pure $ Notify- (getSkipChan skipChan)- (putSkipChan skipChan ())--data SkipChan a =- SkipChan (MVar (a, [MVar ()])) (MVar ())--newSkipChan :: IO (SkipChan a)-newSkipChan = do- sem <- newEmptyMVar- main <- newMVar (undefined, [sem])- return (SkipChan main sem)--putSkipChan :: SkipChan a -> a -> IO ()-putSkipChan (SkipChan main _) v = do- (_, sems) <- takeMVar main- putMVar main (v, [])- mapM_ (\sem -> putMVar sem ()) sems--getSkipChan :: SkipChan a -> IO a-getSkipChan (SkipChan main sem) = do- takeMVar sem- (v, sems) <- takeMVar main- putMVar main (v, sem:sems)- return v+ (takeMVar mvar)+ (() <$ do tryPutMVar mvar $! ())