|
| 1 | +{-# LANGUAGE CPP #-} |
| 2 | +{-# OPTIONS_GHC -Wno-orphans #-} |
| 3 | + |
| 4 | +module Functora.Miso.Prelude |
| 5 | + ( module X, |
| 6 | + inspect, |
| 7 | + consoleLog, |
| 8 | + ) |
| 9 | +where |
| 10 | + |
| 11 | +#if defined(__GHCJS__) || defined(ghcjs_HOST_OS) || defined(wasi_HOST_OS) |
| 12 | +import qualified Data.Binary as Binary (get, put) |
| 13 | +#endif |
| 14 | +import Functora.Cfg as X |
| 15 | +import Functora.Prelude as X hiding |
| 16 | + ( Field (..), |
| 17 | + String, |
| 18 | + Text, |
| 19 | + field, |
| 20 | + inspect, |
| 21 | + ) |
| 22 | +import qualified Functora.Prelude as Prelude |
| 23 | +import Miso as X hiding |
| 24 | + ( Key, |
| 25 | + URI, |
| 26 | + at, |
| 27 | + consoleLog, |
| 28 | + for_, |
| 29 | + view, |
| 30 | + ) |
| 31 | +import qualified Miso |
| 32 | +import Miso.String as X |
| 33 | + ( FromMisoString, |
| 34 | + MisoString, |
| 35 | + ToMisoString, |
| 36 | + fromMisoString, |
| 37 | + toMisoString, |
| 38 | + ) |
| 39 | +import Type.Reflection |
| 40 | + |
| 41 | +#if defined(__GHCJS__) || defined(ghcjs_HOST_OS) || defined(wasi_HOST_OS) |
| 42 | +instance Binary MisoString where |
| 43 | + put = Binary.put . fromMisoString @Prelude.Text |
| 44 | + get = fmap (toMisoString @Prelude.Text) Binary.get |
| 45 | + |
| 46 | +instance From Prelude.Text MisoString where |
| 47 | + from = toMisoString |
| 48 | + |
| 49 | +instance From Prelude.String MisoString where |
| 50 | + from = toMisoString |
| 51 | + |
| 52 | +instance From MisoString Prelude.Text where |
| 53 | + from = fromMisoString |
| 54 | + |
| 55 | + |
| 56 | +instance From MisoString Prelude.String where |
| 57 | + from = fromMisoString |
| 58 | + |
| 59 | +instance ConvertUtf8 MisoString ByteString where |
| 60 | + encodeUtf8 = encodeUtf8 . from @MisoString @Prelude.Text |
| 61 | + decodeUtf8 = from @Prelude.Text @MisoString . decodeUtf8 |
| 62 | + decodeUtf8Strict = fmap (from @Prelude.Text @MisoString) . decodeUtf8Strict |
| 63 | +#endif |
| 64 | + |
| 65 | +inspect :: (Show a, Data a) => a -> MisoString |
| 66 | +inspect x = |
| 67 | + case typeOf x `eqTypeRep` typeRep @MisoString of |
| 68 | + Just HRefl -> x |
| 69 | + Nothing -> toMisoString $ Prelude.inspect @Prelude.Text x |
| 70 | + |
| 71 | +consoleLog :: (Show a, Data a) => a -> JSM () |
| 72 | +consoleLog = Miso.consoleLog . inspect |
0 commit comments