on develop help sign in
Use Aeson.decode on ghc for jsonDecode
commitb1f236a97a4a90db70723a0b59dec02f463e6101 authorLuigy Leon <luigy@outlook.com> dateMon 5 Feb 2018, 20:39 (9 years ago) parent18d6776
1 file changed+4
reflex-dom-core/src/Foreign/JavaScript/Utils.hs+4
reflex-dom-core/src/Foreign/JavaScript/Utils.hs+4
@@ -36,11 +36,15 @@ bsToArrayBuffer bs = liftJSM $ do
3636 js_dataView off len ref
3737
3838jsonDecode :: FromJSON a => JSString -> Maybe a
39+#ifdef ghcjs_HOST_OS
3940jsonDecode t = do
4041 result <- unsafePerformIO $ (fromJSVal =<< js_jsonParse t) `catch` (\(_ :: SomeException) -> pure Nothing)
4142 case fromJSON result of
4243 Success a -> Just a
4344 Error _ -> Nothing
45+#else
46+jsonDecode = decode . LBS.fromStrict . encodeUtf8 . textFromJSString
47+#endif
4448
4549js_jsonParse :: JSString -> JSM JSVal
4650js_jsonParse a = jsg "JSON" ^. js1 "parse" a