Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ffi/ghc/Miso/DSL/FFI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ isUndefined_ffi = undefined
freeFunction_ffi :: JSVal -> IO ()
freeFunction_ffi = undefined
-----------------------------------------------------------------------------
-- | Schedules a callback to run before the next repaint.
requestAnimationFrame :: JSVal -> IO Int
requestAnimationFrame = undefined
-----------------------------------------------------------------------------
-- | Cancels a previously-scheduled 'requestAnimationFrame' callback.
cancelAnimationFrame :: Int -> IO ()
cancelAnimationFrame = undefined
-----------------------------------------------------------------------------
Expand Down
300 changes: 150 additions & 150 deletions src/Miso.hs

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/Miso/Binding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
--
-- miso includes an experimental feature that allows fields of different models to be synchronized
-- against each another in response to model changes. See 'Miso.Binding'. Note this feature is
-- experimental, it is recommended to use asynchronous Component communication (like 'broadcast') by default.
-- experimental, it is recommended to use asynchronous Component communication (like 'Miso.Runtime.broadcast') by default.
--
-- This module exposes combinators to construct a 'Binding' which holds two lenses that will alter
-- t'Component' model state along the parent-child relationship using a 'Lens'. Practically, this means when
-- one t'Component' is marked as dirty, another t'Component' will also potentially will be marked as
-- t'Miso.Types.Component' model state along the parent-child relationship using a t'Miso.Lens.Lens'. Practically, this means when
-- one t'Miso.Types.Component' is marked as dirty, another t'Miso.Types.Component' will also potentially will be marked as
-- dirty if they are connected along an edge ('Binding').
--
-- See the [miso-reactive](https://github.com/haskell-miso/miso-reactive) project for more information.
Expand Down Expand Up @@ -70,7 +70,7 @@ data Binding parent child
| forall field . Bidirectional Precedence (parent -> field) (field -> parent -> parent) (child -> field) (field -> child -> child)
-----------------------------------------------------------------------------
-- | Data type used to express if the Child state should take precendence
-- over the parent state during 'Component' mount.
-- over the parent state during t'Miso.Types.Component' 'Miso.Types.mount'.
data Precedence = Child | Parent
deriving (Eq, Show)
-----------------------------------------------------------------------------
Expand Down Expand Up @@ -109,7 +109,7 @@ p <---> c = Bidirectional Parent (get_ p) (set_ p) (get_ c) (set_ c)
get_ lens_ record = getConst (lens_ Const record)
set_ lens_ field = runIdentity . lens_ (\_ -> Identity field)
-----------------------------------------------------------------------------
-- | Like '<--->' but biases to inherit 'Parent' state on 'Component' 'mount'.
-- | Like '<--->' but biases to inherit 'Parent' state on t'Miso.Types.Component' 'Miso.Types.mount'.
--
-- @since 1.10.0.0
(<--->>)
Expand All @@ -121,7 +121,7 @@ l <--->> r =
Bidirectional _ w x y z -> Bidirectional Parent w x y z
_ -> error "impossible"
-----------------------------------------------------------------------------
-- | Like '<--->' but biases to inherit 'Child' state on 'Component' 'mount'.
-- | Like '<--->' but biases to inherit 'Child' state on t'Miso.Types.Component' 'Miso.Types.mount'.
--
-- @since 1.10.0.0
(<<--->)
Expand All @@ -144,7 +144,7 @@ p ---> c = ParentToChild (get_ p) (set_ c)
get_ lens_ record = getConst (lens_ Const record)
set_ lens_ field = runIdentity . lens_ (\_ -> Identity field)
-----------------------------------------------------------------------------
-- | Like '<-->' but biases to inherit 'Parent' state on 'Component' 'mount'.
-- | Like '<-->' but biases to inherit 'Parent' state on t'Miso.Types.Component' 'Miso.Types.mount'.
--
-- @since 1.10.0.0
(<-->>)
Expand All @@ -156,7 +156,7 @@ l <-->> r =
Bidirectional _ w x y z -> Bidirectional Parent w x y z
_ -> error "impossible"
-----------------------------------------------------------------------------
-- | Like '<-->' but biases to inherit 'Child' state on 'Component' 'mount'.
-- | Like '<-->' but biases to inherit 'Child' state on t'Miso.Types.Component' 'Miso.Types.mount'.
--
-- @since 1.10.0.0
(<<-->)
Expand Down
9 changes: 8 additions & 1 deletion src/Miso/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ class ToJSVal a where
gToJSVal (from x) o
toJSVal o
-----------------------------------------------------------------------------
-- | Generic helper for marshaling record fields into a JavaScript t'Object'.
-- Used by the default 'ToJSVal' implementation; not normally called directly.
class GToJSVal (f :: Type -> Type) where
-- | Write the fields of @f a@ into the given t'Object'.
gToJSVal :: f a -> Object -> IO ()
-----------------------------------------------------------------------------
instance GToJSVal a => GToJSVal (D1 i a) where
Expand Down Expand Up @@ -237,7 +240,10 @@ class FromJSVal a where
Nothing -> error "fromJSValUnchecked: failure"
Just y -> pure y
-----------------------------------------------------------------------------
-- | Generic helper for unmarshaling JavaScript t'Object' fields into Haskell record fields.
-- Used by the default 'FromJSVal' implementation; not normally called directly.
class GFromJSVal (f :: Type -> Type) where
-- | Read the fields of @f a@ from the given t'Object'.
gFromJSVal :: Object -> IO (Maybe (f a))
-----------------------------------------------------------------------------
instance GFromJSVal a => GFromJSVal (D1 i a) where
Expand Down Expand Up @@ -492,6 +498,7 @@ infixr 2 #
invokeFunction func o' args'
{-# INLINABLE (#) #-}
-----------------------------------------------------------------------------
-- | Invoke a t'Function' with the given arguments and unmarshal the result.
apply :: (FromJSVal a, ToArgs args) => Function -> args -> IO a
apply (Function func) args = do
o <- toJSVal global
Expand All @@ -514,7 +521,7 @@ create = Object <$> create_ffi
{-# INLINABLE create #-}
-----------------------------------------------------------------------------
-- | Creates a new JS t'Object' populated with key-value pairs specified
-- in the list. Meant for use with 'inline' JS functionality.
-- in the list. Meant for use with 'Miso.FFI.Internal.inline' JS functionality.
--
-- @
-- update = \case
Expand Down
6 changes: 4 additions & 2 deletions src/Miso/Data/Array.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
-- Stability : experimental
-- Portability : non-portable
--
-- Mutable 'Array' data structure in 'IO'.
-- Mutable t'Array' data structure in 'IO'.
--
-- A JavaScript [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array). This is a convenience for manipulating JavaScript data structures from Haskell.
--
Expand Down Expand Up @@ -52,6 +52,8 @@ import qualified Miso.DSL as DSL
import Miso.FFI (callFunction)
import Miso.String (ms, unpack)
-----------------------------------------------------------------------------
-- | Typed wrapper around a JavaScript
-- [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).
newtype Array value = Array JSVal deriving (FromJSVal, ToJSVal, ToObject)
-----------------------------------------------------------------------------
-- | Constructs a new JS [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) in t'IO'.
Expand Down Expand Up @@ -92,7 +94,7 @@ size (Array m) = DSL.fromJSValUnchecked =<< m ! "length"
null :: Array value -> IO Bool
null m = (== 0) <$> size m
-----------------------------------------------------------------------------
-- | Checks existence of 'value' in t'Array', returns t'Bool.
-- | Checks existence of @value@ in t'Array', returns t'Bool'.
member :: ToJSVal value => value -> Array value -> IO Bool
member value (Array m) = DSL.fromJSValUnchecked =<< callFunction m "includes" =<< DSL.toJSVal value
-----------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions src/Miso/Data/Map.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-- Stability : experimental
-- Portability : non-portable
--
-- Mutable 'Map' data structure in 'IO'.
-- Mutable t'Map' data structure in 'IO'.
--
-- A JavaScript [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map). This is a convenience for manipulating JavaScript data structures from Haskell.
--
Expand Down Expand Up @@ -41,6 +41,8 @@ import Miso.DSL (jsg, JSVal, ToJSVal, FromJSVal, (!))
import qualified Miso.DSL as DSL
import Miso.FFI (callFunction)
-----------------------------------------------------------------------------
-- | Typed wrapper around a JavaScript
-- [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map).
newtype Map key value = Map JSVal deriving (FromJSVal, ToJSVal)
-----------------------------------------------------------------------------
-- | Constructs a new JS [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) in t'IO'.
Expand All @@ -66,7 +68,7 @@ clear (Map m) = void (callFunction m "clear" ())
size :: Map key value -> IO Int
size (Map m) = DSL.fromJSValUnchecked =<< m ! "size"
-----------------------------------------------------------------------------
-- | Checks existence of a value by 'key', returns t'Bool.
-- | Checks existence of a value by @key@, returns t'Bool'.
has :: ToJSVal key => key -> Map key value -> IO Bool
has key (Map m) = DSL.fromJSValUnchecked =<< callFunction m "has" =<< DSL.toJSVal key
-----------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions src/Miso/Data/Set.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-- Stability : experimental
-- Portability : non-portable
--
-- Mutable 'Set' data structure in 'IO'.
-- Mutable t'Set' data structure in 'IO'.
--
-- A JavaScript [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set). This is a convenience for manipulating JavaScript data structures from Haskell.
--
Expand Down Expand Up @@ -46,6 +46,8 @@ import Miso.DSL (jsg, JSVal, ToJSVal, FromJSVal, (!))
import qualified Miso.DSL as DSL
import Miso.FFI (callFunction)
-----------------------------------------------------------------------------
-- | Typed wrapper around a JavaScript
-- [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set).
newtype Set key = Set JSVal deriving (FromJSVal, ToJSVal)
-----------------------------------------------------------------------------
-- | Constructs a new JS [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) in t'IO'.
Expand All @@ -67,7 +69,7 @@ clear (Set m) = void (callFunction m "clear" ())
size :: Set key -> IO Int
size (Set m) = DSL.fromJSValUnchecked =<< m ! "size"
-----------------------------------------------------------------------------
-- | Checks existence of 'key' in t'Set', returns t'Bool.
-- | Checks existence of @key@ in t'Set', returns t'Bool'.
member :: ToJSVal key => key -> Set key -> IO Bool
member key (Set m) = DSL.fromJSValUnchecked =<< callFunction m "has" =<< DSL.toJSVal key
-----------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/Miso/Date.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-- Stability : experimental
-- Portability : non-portable
--
-- Mutable 'Date' data structure in 'IO'.
-- Mutable t'Date' data structure in 'IO'.
--
-- A JavaScript [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date). This is a convenience for manipulating JavaScript data structures from Haskell.
--
Expand Down Expand Up @@ -79,6 +79,8 @@ import qualified Miso.DSL as DSL
import Miso.FFI (callFunction)
import Miso.String (MisoString)
-----------------------------------------------------------------------------
-- | Typed wrapper around a JavaScript
-- [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date).
newtype Date = Date JSVal deriving (FromJSVal, ToJSVal, ToObject, Eq)
-----------------------------------------------------------------------------
-- | Constructs a new JS [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) in t'IO'.
Expand Down
18 changes: 9 additions & 9 deletions src/Miso/Effect.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ mkComponentInfo = ComponentInfo
-----------------------------------------------------------------------------
-- | This is the 'Reader r' in t'Miso.Effect'. Accessible via 'Control.Monad.Reader.ask'. It holds
-- a phantom type for @parent@. This is used as a witness when calling the
-- 'parent' function. It gives access to 'Component' metadata such as the 'DOMRef' the
-- 'Component' was mounted on and the 'ComponentId' associated with it.
-- 'Miso.Runtime.parent' function. It gives access to t'Miso.Types.Component' metadata such as the 'DOMRef' the
-- t'Miso.Types.Component' was mounted on and the 'ComponentId' associated with it.
data ComponentInfo parent props
= ComponentInfo
{ _componentInfoId :: ComponentId
Expand Down Expand Up @@ -218,12 +218,12 @@ batch_ actions = sequence_
-----------------------------------------------------------------------------
-- | A monad for succinctly expressing model transitions in the @update@ function.
--
-- t'Effect' is a @RWS@, where the @State@ allows modification to 'model'.
-- t'Effect' is a @RWS@, where the @State@ allows modification to @model@.
-- It's also a @Writer@ @Monad@, where the accumulator is a list of scheduled
-- @IO@ actions. Multiple actions can be scheduled using 'Control.Monad.Writer.Class.tell'
-- from the @mtl@ library and a single asynchronous action can be scheduled using 'io_'.
--
-- An t'Effect' represents the results of an 'update' action.
-- An t'Effect' represents the results of an @update@ action.
--
-- It consists of the updated model and a list of subscriptions. Each t'Sub' is
-- run in a new thread so there is no risk of accidentally blocking the
Expand All @@ -243,8 +243,8 @@ batch_ actions = sequence_
-- MyAction2 -> do
-- field2 '%=' f
-- 'io_' $ do
-- 'consoleLog' \"Hello\"
-- 'consoleLog' \"World!\"
-- 'Miso.FFI.consoleLog' \"Hello\"
-- 'Miso.FFI.consoleLog' \"World!\"
-- , ...
-- }
-- @
Expand Down Expand Up @@ -385,7 +385,7 @@ modifyAllIO f = censor $ \actions ->
-- to turn events into actions.
--
-- @
-- 'update' FetchJSON = 'withSink' $ \\sink -> getJSON (sink . ReceivedJSON) (sink . HandleError)
-- update FetchJSON = 'withSink' $ \\sink -> getJSON (sink . ReceivedJSON) (sink . HandleError)
-- @
--
-- @since 1.9.0.0
Expand All @@ -401,8 +401,8 @@ withSink f = tell [ async f ]
-- data Action = HelloWorld
-- type Model = Int
--
-- 'update' :: Action -> 'Effect' parent Model Action
-- 'update' = \\case
-- update :: Action -> 'Effect' parent Model Action
-- update = \\case
-- Click -> 'issue' HelloWorld
-- @
--
Expand Down
6 changes: 3 additions & 3 deletions src/Miso/FFI/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ updateRef jsval1 jsval2 = do
-- logNameGetAge :: Person -> IO Int
-- logNameGetAge = inline
-- """
-- console.log('name', name);
-- console.log("name", name);
-- return age;
-- """
--
Expand Down Expand Up @@ -604,7 +604,7 @@ addScript useModule js_ = do
void $ context # "appendChild" $ (head_, script)
pure script
-----------------------------------------------------------------------------
-- | Sets the @.value@ property on a 'DOMRef'.
-- | Sets the @.value@ property on a t'Miso.Effect.DOMRef'.
--
-- Useful for resetting the @value@ property on an input element.
--
Expand Down Expand Up @@ -1128,7 +1128,7 @@ newCustomEvent :: ToArgs args => args -> IO Event
{-# INLINABLE newCustomEvent #-}
newCustomEvent args = Event <$> new (jsg "CustomEvent") args
-----------------------------------------------------------------------------
-- | Uses the 'splitmix' function to generate a PRNG.
-- | Uses the @splitmix@ function to generate a PRNG.
--
splitmix32 :: Double -> IO JSVal
{-# INLINABLE splitmix32 #-}
Expand Down
2 changes: 1 addition & 1 deletion src/Miso/FFI/QQ.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extQ f g a = maybe (f a) g (cast a)
withString :: (Quote m, Typeable a) => a -> Maybe (m Exp)
withString a = liftString <$> cast a
----------------------------------------------------------------------------
-- | Use `isPrefixOf` as you traverse the string in lex order and do a replace
-- | Use 'Data.List.isPrefixOf' as you traverse the string in lex order and do a replace
formatVars :: MisoString -> [(MisoString, MisoString)] -> MisoString
formatVars s [] = s
formatVars s table@((var,key):xs) =
Expand Down
Loading
Loading