packages feed

javascript-extras 0.4.0.0 → 0.5.0.0

raw patch · 4 files changed

+28/−18 lines, 4 filesdep +newtype-genericsdep ~ghcjs-base-stubPVP ok

version bump matches the API change (PVP)

Dependencies added: newtype-generics

Dependency ranges changed: ghcjs-base-stub

API changes (from Hackage documentation)

+ JavaScript.Extras.JSRep: instance Control.Newtype.Generics.Newtype JavaScript.Extras.JSRep.JSRep
+ JavaScript.Extras.JSRep: instance GHC.Generics.Generic JavaScript.Extras.JSRep.JSRep
- JavaScript.Extras.Property: getProperty :: ToJS a => a -> JSString -> IO JSRep
+ JavaScript.Extras.Property: getProperty :: ToJS j => JSString -> j -> IO JSRep
- JavaScript.Extras.Property: setProperty :: ToJS a => a -> Property -> IO ()
+ JavaScript.Extras.Property: setProperty :: ToJS j => Property -> j -> IO ()

Files

README.md view
@@ -4,6 +4,10 @@  # Changelog +* 0.5.0.0+  - flipped the args of `getProperty` and `setProperty`+    This makes it easier for chaining.+ * 0.4.0.0   - Renamed `JSVar` to `JSRep` to avoid confusion with `JSVal`   - Renamed `toJS'` to `toJSR`
javascript-extras.cabal view
@@ -1,5 +1,5 @@ name:                javascript-extras-version:             0.4.0.0+version:             0.5.0.0 synopsis:            Extra javascript functions when using GHCJS description:         Extra javascript functions when using GHCJS homepage:            https://github.com/louispan/javascript-extras#readme@@ -24,6 +24,7 @@                        JavaScript.Extras.JSRep.Unsafe   build-depends:       base >= 4.7 && < 5                      , deepseq >= 1.4+                     , newtype-generics >= 0.5                      , parallel >= 3.2                      , text >= 1.2   default-language:    Haskell2010@@ -31,7 +32,7 @@   if impl(ghcjs)     build-depends: ghcjs-base   if !impl(ghcjs)-    build-depends: ghcjs-base-stub >= 0.1.0.1+    build-depends: ghcjs-base-stub >= 0.2  executable javascript-extras-test   hs-source-dirs:      test/hs@@ -46,7 +47,7 @@     build-depends: ghcjs-base                  , ghcjs-prim >= 0.1   if !impl(ghcjs)-    build-depends: ghcjs-base-stub >= 0.1.0.2+    build-depends: ghcjs-base-stub >= 0.2  source-repository head   type:     git
src/JavaScript/Extras/JSRep.hs view
@@ -1,18 +1,23 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE DeriveGeneric #-}  module JavaScript.Extras.JSRep where  import Control.DeepSeq+import Control.Newtype.Generics import Data.Coerce import Data.JSString as JS import Data.String+import GHC.Generics import qualified GHCJS.Marshal.Pure as J import qualified GHCJS.Types as J import JavaScript.Extras.Cast as JE  -- | Wrapper to have a JSVal that also have an IString instance -- This is helpful when using OverloadedStrings-newtype JSRep = JSRep J.JSVal+newtype JSRep = JSRep J.JSVal deriving (Generic)++instance Newtype JSRep  instance Show JSRep where     show = JS.unpack . js_stringify
src/JavaScript/Extras/Property.hs view
@@ -32,22 +32,22 @@ classNames = JE.toJSR . JS.unwords . fmap fst . filter snd  -- | get a property of any JSVal. If a null or undefined is queried, the result will also be null-getProperty :: JE.ToJS a => a -> J.JSString -> IO JE.JSRep-getProperty a k = let k' = J.pToJSVal k-                      x = JE.toJS a+getProperty :: JE.ToJS j => J.JSString -> j -> IO JE.JSRep+getProperty k j = let k' = J.pToJSVal k+                      x = JE.toJS j                   in if J.isUndefined x || J.isNull x                          || J.isUndefined k' || J.isNull k'                      then pure $ JE.JSRep J.nullRef-                     else js_unsafeGetProperty x k+                     else js_unsafeGetProperty k x  -- | set a property of any JSVal-setProperty :: JE.ToJS a => a -> Property -> IO ()-setProperty a (k, v) = let k' = J.pToJSVal k-                           x = JE.toJS a+setProperty :: JE.ToJS j => Property -> j -> IO ()+setProperty (k, v) j = let k' = J.pToJSVal k+                           x = JE.toJS j                     in if J.isUndefined x || J.isNull x                           || J.isUndefined k' || J.isNull k'                        then pure ()-                       else js_unsafeSetProperty x k v+                       else js_unsafeSetProperty k v x  fromProperties :: [Property] -> JO.Object fromProperties xs =@@ -64,13 +64,13 @@  -- | throws an exception if undefined or null foreign import javascript unsafe-  "$1[$2]"-  js_unsafeGetProperty :: J.JSVal -> J.JSString -> IO JE.JSRep+  "$2[$1]"+  js_unsafeGetProperty :: J.JSString -> J.JSVal -> IO JE.JSRep  -- | throws an exception if undefined or null foreign import javascript unsafe-  "$1[$2] = $3;"-  js_unsafeSetProperty :: J.JSVal -> J.JSString -> JE.JSRep -> IO ()+  "$3[$1] = $2;"+  js_unsafeSetProperty :: J.JSString -> JE.JSRep -> J.JSVal -> IO ()  -- | zip list of string and JSVal to object, lists must have been completely forced first -- Using the idea from JavaScript.Array.Internal.fromList h$fromHsListJSVal@@ -81,11 +81,11 @@ #else  -- | throws an exception if undefined or null-js_unsafeGetProperty :: J.JSVal -> J.JSString -> IO JE.JSRep+js_unsafeGetProperty :: J.JSString -> J.JSVal -> IO JE.JSRep js_unsafeGetProperty _ _ = pure $ JE.JSRep J.nullRef  -- | throws an exception if undefined or null-js_unsafeSetProperty :: J.JSVal -> J.JSString -> JE.JSRep -> IO ()+js_unsafeSetProperty :: J.JSString -> JE.JSRep -> J.JSVal -> IO () js_unsafeSetProperty _ _ _ = pure ()  -- | zip list of string and JSVal to object, lists must have been completely forced first