diff options
author | Joris | 2019-10-20 22:08:31 +0200 |
---|---|---|
committer | Joris | 2019-10-20 22:08:31 +0200 |
commit | 33e78f2ebbf5bf7b40e7aa732cc7c019f6df3f12 (patch) | |
tree | bc325950963bcb5c27e1aaba2a4ee7e092efbcd4 /client/src/Model | |
parent | 602c52acfcfa494b07fec05c20b317b60ea8a6f3 (diff) |
Simplify page initialization
Diffstat (limited to 'client/src/Model')
-rw-r--r-- | client/src/Model/Loadable.hs | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/client/src/Model/Loadable.hs b/client/src/Model/Loadable.hs deleted file mode 100644 index 3076b46..0000000 --- a/client/src/Model/Loadable.hs +++ /dev/null @@ -1,51 +0,0 @@ -module Model.Loadable - ( Loadable (..) - , fromEvent - , view - ) where - -import Reflex.Dom (MonadWidget) -import qualified Reflex.Dom as R - -import Data.Functor (Functor) -import Data.Text (Text) -import Reflex.Dom (Dynamic, Event, MonadWidget) -import qualified Reflex.Dom as R - -data Loadable t - = Loading - | Error Text - | Loaded t - -instance Functor Loadable where - fmap f Loading = Loading - fmap f (Error e) = Error e - fmap f (Loaded x) = Loaded (f x) - -instance Applicative Loadable where - pure x = Loaded x - - Loading <*> _ = Loading - (Error e) <*> _ = Error e - (Loaded f) <*> Loading = Loading - (Loaded f) <*> (Error e) = Error e - (Loaded f) <*> (Loaded x) = Loaded (f x) - -instance Monad Loadable where - Loading >>= f = Loading - (Error e) >>= f = Error e - (Loaded x) >>= f = f x - -fromEvent :: forall t m a. MonadWidget t m => Event t (Either Text a) -> m (Dynamic t (Loadable a)) -fromEvent = - R.foldDyn - (\res _ -> case res of - Left err -> Error err - Right t -> Loaded t - ) - Loading - -view :: forall t m a. MonadWidget t m => (a -> m ()) -> Loadable a -> m () -view _ (Loading) = R.divClass "pageSpinner" $ R.divClass "spinner" $ R.blank -view _ (Error e) = R.text e -view f (Loaded x) = f x |