miso 0.19.0.0 → 0.20.0.0
raw patch · 6 files changed
+55/−9 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Miso.Util: (=:) :: k -> a -> Map k a
Files
- ghcjs-src/Miso/Effect.hs +12/−0
- ghcjs-src/Miso/Subscription/Window.hs +0/−3
- ghcjs-src/Miso/Types.hs +30/−4
- miso.cabal +1/−1
- src/Miso/Util.hs +11/−0
- tests/Main.hs +1/−1
ghcjs-src/Miso/Effect.hs view
@@ -12,9 +12,11 @@ , module Miso.Effect.XHR , module Miso.Effect.DOM , Effect (..), Sub, Sink+, mapSub , noEff , (<#) , (#>)+, batchEff , effectSub ) where @@ -40,6 +42,12 @@ -- | Function to asynchronously dispatch actions to the 'update' function. type Sink action = action -> IO () +-- | Turn a subscription that consumes actions of type @a@ into a subscription+-- that consumes actions of type @b@ using the supplied function of type @a -> b@.+mapSub :: (actionA -> actionB) -> Sub actionA -> Sub actionB+mapSub f sub = \sinkB -> let sinkA = sinkB . f+ in sub sinkA+ instance Functor (Effect action) where fmap f (Effect m acts) = Effect (f m) acts @@ -67,6 +75,10 @@ -- | `Effect` smart constructor, flipped (#>) :: IO action -> model -> Effect action model (#>) = flip (<#)++-- | `Smart constructor for an 'Effect' with multiple actions.+batchEff :: model -> [IO action] -> Effect action model+batchEff model actions = Effect model $ (>>=) <$> actions -- | Like '<#' but schedules a subscription which is an IO computation which has -- access to a 'Sink' which can be used to asynchronously dispatch actions to
ghcjs-src/Miso/Subscription/Window.hs view
@@ -24,9 +24,6 @@ import Miso.Html.Internal ( Sub ) import Miso.String -import Miso.String-import Miso.Event- import Data.Aeson.Types (parseEither) -- | Captures window coordinates changes as they occur and writes them to
ghcjs-src/Miso/Types.hs view
@@ -14,16 +14,21 @@ -- * The Transition Monad , Transition+ , mapAction , fromTransition , toTransition , scheduleIO+ , scheduleIO_+ , scheduleIOFor_ , scheduleSub ) where -import Control.Monad.Trans.Class (lift)-import Control.Monad.Trans.State.Strict (StateT(StateT), execStateT)-import Control.Monad.Trans.Writer.Strict (WriterT(WriterT), Writer, runWriter, tell)-import qualified Data.Map as M+import Control.Monad.Trans.Class (lift)+import Control.Monad.Trans.State.Strict (StateT(StateT), execStateT, mapStateT)+import Control.Monad.Trans.Writer.Strict (WriterT(WriterT), Writer, runWriter, tell, mapWriter)+import Data.Bifunctor (second)+import Data.Foldable (Foldable, for_)+import qualified Data.Map as M import Miso.Effect import Miso.Html.Internal import Miso.String@@ -77,6 +82,13 @@ -- @ type Transition action model = StateT model (Writer [Sub action]) +-- | Turn a transition that schedules subscriptions that consume+-- actions of type @a@ into a transition that schedules subscriptions+-- that consume actions of type @b@ using the supplied function of+-- type @a -> b@.+mapAction :: (actionA -> actionB) -> Transition actionA model r -> Transition actionB model r+mapAction = mapStateT . mapWriter . second . fmap . mapSub+ -- | Convert a @Transition@ computation to a function that can be given to 'update'. fromTransition :: Transition action model ()@@ -97,6 +109,20 @@ -- @Control.Monad.Writer.Class.tell@ from the @mtl@ library. scheduleIO :: IO action -> Transition action model () scheduleIO ioAction = scheduleSub $ \sink -> ioAction >>= sink++-- | Like 'scheduleIO' but doesn't cause an action to be dispatched to+-- the 'update' function.+--+-- This is handy for scheduling IO computations where you don't care+-- about their results or when they complete.+scheduleIO_ :: IO () -> Transition action model ()+scheduleIO_ ioAction = scheduleSub $ \_sink -> ioAction++-- | Like `scheduleIO_` but generalized to any instance of `Foldable`+--+-- This is handy for scheduling IO computations that return a `Maybe` value+scheduleIOFor_ :: Foldable f => IO (f action) -> Transition action model ()+scheduleIOFor_ io = scheduleSub $ \sink -> io >>= \m -> for_ m sink -- | Like 'scheduleIO' but schedules a subscription which is an IO -- computation that has access to a 'Sink' which can be used to
miso.cabal view
@@ -1,5 +1,5 @@ name: miso-version: 0.19.0.0+version: 0.20.0.0 category: Web, Miso, Data Structures license: BSD3 license-file: LICENSE
src/Miso/Util.hs view
@@ -10,9 +10,11 @@ module Miso.Util ( withFoldable , conditionalViews+ , (=:) ) where import Data.Foldable+import qualified Data.Map as M import Miso.Html (View) -- | Generic @map@ function, useful for creating @View@s from the elements of@@ -35,3 +37,12 @@ if condition then views else []++-- | Smart constructor for Attributes. This function is helpful when constructing numerous Attributes+-- Example shown below.+-- +-- @ +-- div_ [ style_ $ ("background" =: "red" <> "width" =: "250px" <> "height" =: "250px") ] []+-- @+(=:) :: k -> a -> M.Map k a +a =: b = M.singleton a b
tests/Main.hs view
@@ -19,7 +19,7 @@ import GHCJS.Types import qualified JavaScript.Object.Internal as OI import System.IO.Unsafe-import Test.QuickCheck+import Test.QuickCheck hiding (total) import Test.QuickCheck.Instances import Test.QuickCheck.Monadic