react-flux 1.1.0 → 1.1.1
raw patch · 4 files changed
+85/−23 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ React.Flux.Addons.Intl: dayToJSVal :: Day -> JSVal
+ React.Flux.Addons.Intl: timeToJSVal :: UTCTime -> JSVal
+ React.Flux.PropertiesAndEvents: instance (React.Flux.PropertiesAndEvents.FromJSVal a, React.Flux.PropertiesAndEvents.FromJSVal b) => React.Flux.PropertiesAndEvents.FromJSVal (a, b)
+ React.Flux.PropertiesAndEvents: instance (React.Flux.PropertiesAndEvents.FromJSVal a, React.Flux.PropertiesAndEvents.FromJSVal b, React.Flux.PropertiesAndEvents.FromJSVal c) => React.Flux.PropertiesAndEvents.FromJSVal (a, b, c)
+ React.Flux.PropertiesAndEvents: instance (React.Flux.PropertiesAndEvents.FromJSVal a, React.Flux.PropertiesAndEvents.FromJSVal b, React.Flux.PropertiesAndEvents.FromJSVal c, React.Flux.PropertiesAndEvents.FromJSVal d) => React.Flux.PropertiesAndEvents.FromJSVal (a, b, c, d)
+ React.Flux.PropertiesAndEvents: instance (React.Flux.PropertiesAndEvents.FromJSVal a, React.Flux.PropertiesAndEvents.FromJSVal b, React.Flux.PropertiesAndEvents.FromJSVal c, React.Flux.PropertiesAndEvents.FromJSVal d, React.Flux.PropertiesAndEvents.FromJSVal e) => React.Flux.PropertiesAndEvents.FromJSVal (a, b, c, d, e)
+ React.Flux.PropertiesAndEvents: instance (React.Flux.PropertiesAndEvents.FromJSVal a, React.Flux.PropertiesAndEvents.FromJSVal b, React.Flux.PropertiesAndEvents.FromJSVal c, React.Flux.PropertiesAndEvents.FromJSVal d, React.Flux.PropertiesAndEvents.FromJSVal e, React.Flux.PropertiesAndEvents.FromJSVal f) => React.Flux.PropertiesAndEvents.FromJSVal (a, b, c, d, e, f)
+ React.Flux.PropertiesAndEvents: instance (React.Flux.PropertiesAndEvents.FromJSVal a, React.Flux.PropertiesAndEvents.FromJSVal b, React.Flux.PropertiesAndEvents.FromJSVal c, React.Flux.PropertiesAndEvents.FromJSVal d, React.Flux.PropertiesAndEvents.FromJSVal e, React.Flux.PropertiesAndEvents.FromJSVal f, React.Flux.PropertiesAndEvents.FromJSVal g) => React.Flux.PropertiesAndEvents.FromJSVal (a, b, c, d, e, f, g)
+ React.Flux.PropertiesAndEvents: instance (React.Flux.PropertiesAndEvents.FromJSVal a, React.Flux.PropertiesAndEvents.FromJSVal b, React.Flux.PropertiesAndEvents.FromJSVal c, React.Flux.PropertiesAndEvents.FromJSVal d, React.Flux.PropertiesAndEvents.FromJSVal e, React.Flux.PropertiesAndEvents.FromJSVal f, React.Flux.PropertiesAndEvents.FromJSVal g, React.Flux.PropertiesAndEvents.FromJSVal h) => React.Flux.PropertiesAndEvents.FromJSVal (a, b, c, d, e, f, g, h)
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal ()
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal Data.Aeson.Types.Internal.Value
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal Data.Text.Internal.Text
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Int.Int16
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Int.Int32
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Int.Int8
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Types.Bool
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Types.Char
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Types.Double
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Types.Float
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Types.Int
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Types.Word
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Word.Word16
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Word.Word32
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal GHC.Word.Word8
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal a => React.Flux.PropertiesAndEvents.FromJSVal (GHC.Base.Maybe a)
+ React.Flux.PropertiesAndEvents: instance React.Flux.PropertiesAndEvents.FromJSVal a => React.Flux.PropertiesAndEvents.FromJSVal [a]
Files
- ChangeLog.md +11/−0
- react-flux.cabal +1/−1
- src/React/Flux/Addons/Intl.hs +47/−22
- src/React/Flux/PropertiesAndEvents.hs +26/−0
ChangeLog.md view
@@ -1,3 +1,14 @@+# 1.1.1++* When compiling with GHC (not GHCJS), add fake instances for FromJSVal to allow more programs to compile+ with GHC. (Thanks Sönke Hahn!)++* Export functions `timeToJSVal` and `dateToJSVal` from `React.Flux.Addons.Intl`. These functions, which+ have been used internally for a while, convert a Haskell `Day` or `UTCTime` to a JavaScript date. They+ are useful outside of `react-flux` when you want to pass dates or times to messages.++* Some haddock improvements to `React.Flux.Addons.Intl`.+ # 1.1.0 * Breaking Change - I removed the use of `String` and replaced it with either `Text` or `JSString`
react-flux.cabal view
@@ -1,5 +1,5 @@ name: react-flux-version: 1.1.0+version: 1.1.1 synopsis: A binding to React based on the Flux application architecture for GHCJS category: Web homepage: https://bitbucket.org/wuzzeb/react-flux
src/React/Flux/Addons/Intl.hs view
@@ -87,8 +87,6 @@ -- * Formatting , IntlProperty , iprop- , dayProp- , timeProp -- ** Numbers , int_@@ -105,6 +103,10 @@ , utcTime_ , formattedDate_ , formattedDateProp+ , dayToJSVal+ , timeToJSVal+ , dayProp+ , timeProp -- ** Relative Times , relativeTo_@@ -192,28 +194,14 @@ "$r = (new Date($1, $2-1, $3))" js_mkDate :: Int -> Int -> Int -> JSVal --- | Convert a day to a javascript Date-dayToJSVal :: Day -> JSVal-dayToJSVal day = js_mkDate (fromIntegral y) m d- where- (y, m, d) = toGregorian day- foreign import javascript unsafe "$r = (new Date(Date.UTC($1, $2-1, $3, $4, $5, $6, $7)))" js_mkDateTime :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> JSVal --- | Convert a UTCTime to a javascript date object.-timeToJSVal :: UTCTime -> JSVal-timeToJSVal (UTCTime uday time) = js_mkDateTime (fromIntegral year) month day hour minute sec milli- where- (year, month, day) = toGregorian uday- TimeOfDay hour minute pSec = timeToTimeOfDay time- (sec, fracSec) = properFraction pSec- milli = round $ fracSec * 1000 -- milli is 10^3- foreign import javascript unsafe "$1['intl'][$2]($3, $4)" js_callContextAPI :: JSVal -> JSString -> JSVal -> JSO.Object -> IO JSVal+ #else type JSVal = ()@@ -239,26 +227,63 @@ js_formatHtmlMsg :: JSVal js_formatHtmlMsg = () +class ToJSVal a+instance ToJSVal JSVal+type JSString = String++#endif++-- | Convert a day to a javascript Date. This is useful to pass a date as a property to a+-- 'message'. Note that @JSVal@ is an instance of @ToJSVal@ so the result of 'dayToJSVal' can+-- be passed as a property via '(&=)'. dayToJSVal :: Day -> JSVal+#ifdef __GHCJS__+dayToJSVal day = js_mkDate (fromIntegral y) m d+ where+ (y, m, d) = toGregorian day+#else dayToJSVal _ = ()+#endif +-- | Convert a UTCTime to a javascript date object. This is useful to pass a time as a property+-- to a 'message'. Note that @JSVal@ is an instance of @ToJSVal@ so the result of 'timeToJSVal' can+-- be passed as a property via '(&=)'. timeToJSVal :: UTCTime -> JSVal+#ifdef __GHCJS__+timeToJSVal (UTCTime uday time) = js_mkDateTime (fromIntegral year) month day hour minute sec milli+ where+ (year, month, day) = toGregorian uday+ TimeOfDay hour minute pSec = timeToTimeOfDay time+ (sec, fracSec) = properFraction pSec+ milli = round $ fracSec * 1000 -- milli is 10^3+#else timeToJSVal _ = ()--class ToJSVal a-instance ToJSVal JSVal-type JSString = String #endif -+-- | A property and value that is passed to the intl elements below in situations where+-- React elements can not be used.+--+-- Some of the intl elements below such as 'message' (among others) allow other React elements to+-- be passed as properties. In this case, 'PropertyOrHandler' is used as the+-- type for the parameters and elements can be passed using 'elementProperty'.+-- But for some intl elements below such as 'messageProp', a limitation on the internals of this+-- @react-flux@ package disallow element properties to be created and so only basic javascript+-- values can be passed. In these situations, the type 'IntlProperty' is used to restrict the+-- properties to basic javascript values. data IntlProperty = forall ref. ToJSVal ref => IntlProperty JSString ref +-- | Create an 'IntlProperty' from a property name and anything that can be converted to a+-- javascript value. (@ToJSVal@ lives in @GHCJS.Foreign.Marshal@ module in the @ghcjs-base@ package.) iprop :: ToJSVal v => JSString -> v -> IntlProperty iprop = IntlProperty +-- | Convert a day to a javascript date and set it as a property. This is primarily useful to be able+-- to pass a date as a property to 'messageProp'. dayProp :: JSString -> Day -> IntlProperty dayProp n d = IntlProperty n (dayToJSVal d) +-- | Convert a 'UTCTime' to a javascript date and set it as a property. This is primarily useful to+-- be able to pass a time as a property to 'messageProp'. timeProp :: JSString -> UTCTime -> IntlProperty timeProp n t = IntlProperty n (timeToJSVal t)
src/React/Flux/PropertiesAndEvents.hs view
@@ -99,6 +99,8 @@ import qualified Data.Text as T import qualified Data.Aeson as A import qualified Data.HashMap.Strict as M+import Data.Word+import Data.Int import React.Flux.Internal import React.Flux.Store@@ -117,6 +119,30 @@ type JSVal = () type JSArray = () class FromJSVal a+instance FromJSVal ()+instance FromJSVal a => FromJSVal [a]+instance FromJSVal a => FromJSVal (Maybe a)+instance FromJSVal T.Text+instance FromJSVal Char+instance FromJSVal Bool+instance FromJSVal Int+instance FromJSVal Int8+instance FromJSVal Int16+instance FromJSVal Int32+instance FromJSVal Word+instance FromJSVal Word8+instance FromJSVal Word16+instance FromJSVal Word32+instance FromJSVal Float+instance FromJSVal Double+instance FromJSVal A.Value+instance (FromJSVal a, FromJSVal b) => FromJSVal (a,b)+instance (FromJSVal a, FromJSVal b, FromJSVal c) => FromJSVal (a,b,c)+instance (FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d) => FromJSVal (a,b,c,d)+instance (FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e) => FromJSVal (a,b,c,d,e)+instance (FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e, FromJSVal f) => FromJSVal (a,b,c,d,e,f)+instance (FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e, FromJSVal f, FromJSVal g) => FromJSVal (a,b,c,d,e,f,g)+instance (FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e, FromJSVal f, FromJSVal g, FromJSVal h) => FromJSVal (a,b,c,d,e,f,g,h) class IsJSVal a nullRef :: () nullRef = ()