| Copyright | (c) Matt Hunzinger 2026 |
|---|---|
| License | BSD-style (see the LICENSE file in the distribution) |
| Maintainer | matt@hunzinger.me |
| Stability | provisional |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Concoct.View.Internal
Description
Synopsis
- class Monad m => MonadView (t :: Type -> Type) (m :: Type -> Type) | m -> t where
- useState :: Typeable a => t a -> m (StateRef a)
- useRef :: Typeable a => t a -> m (ViewRef a)
- useEffect :: (Eq d, Typeable d) => t d -> (d -> t ()) -> m ()
- useOnUnmount :: t () -> m ()
- component :: (forall (x :: Type -> Type). MonadView t x => x ()) -> m ()
- liftView :: t () -> m ()
- switchView :: t Bool -> (forall (x :: Type -> Type). MonadView t x => x ()) -> (forall (x :: Type -> Type). MonadView t x => x ()) -> m ()
- listView :: (Typeable a, Eq a) => t [a] -> (a -> forall (x :: Type -> Type). MonadView t x => x ()) -> m ()
- data StateRef a = StateRef {
- stateRef :: IORef a
- stateRefUpdater :: IO () -> IO ()
- readStateRef :: MonadIO m => StateRef a -> m a
- writeStateRef :: MonadIO m => StateRef a -> a -> m ()
- newtype ViewRef a = ViewRef a
- readViewRef :: Applicative m => ViewRef a -> m a
- data Stack = Stack {
- stackBefore :: [Dynamic]
- stackAfter :: [Dynamic]
- emptyStack :: Stack
- pushStack :: Typeable a => a -> Stack -> Stack
- popStack :: Typeable a => Stack -> (Maybe a, Stack)
- peekStack :: Typeable a => Stack -> Maybe a
- setStack :: Typeable a => a -> Stack -> Stack
- skipStack :: Stack -> Stack
- flushStack :: Stack -> Stack
- data ViewState = ViewState {
- viewStack :: Stack
- viewUpdater :: IO () -> IO ()
- rebuildState :: forall (m :: Type -> Type) a. (MonadIO m, Typeable a) => StateT ViewState m (StateRef a)
- rebuildState' :: Typeable a => Stack -> (StateRef a, Stack)
- rebuildRef :: forall (m :: Type -> Type) a. (Monad m, Typeable a) => StateT ViewState m (ViewRef a)
- rebuildRef' :: Typeable a => Stack -> (ViewRef a, Stack)
- rebuildComponent :: forall (m :: Type -> Type) (t :: Type -> Type) f. (MonadIO m, MonadView t f) => (f () -> StateT ViewState m ()) -> (forall (x :: Type -> Type). MonadView t x => x ()) -> StateT ViewState m ()
MonadView
class Monad m => MonadView (t :: Type -> Type) (m :: Type -> Type) | m -> t where Source #
Monadic view.
Views are interpreted in multiple passes:
- Build
- Rebuild
- Skip
- Unmount
And can be extended for further passes, such as layout or render.
Hooks provide access to values in a view across passes.
Views are seperated into components, with each providing a scope for updates to occur.
A component will only be rebuilt if its state is changed.
If a component containing children is updated, its children are rebuilt as well.
Methods
useState :: Typeable a => t a -> m (StateRef a) Source #
Hook to use a mutable state reference.
useRef :: Typeable a => t a -> m (ViewRef a) Source #
Hook to use a constant view reference.
useEffect :: (Eq d, Typeable d) => t d -> (d -> t ()) -> m () Source #
Hook to use an effect that runs when dependencies change.
useOnUnmount :: t () -> m () Source #
Hook that runs when the current component is unmounted.
component :: (forall (x :: Type -> Type). MonadView t x => x ()) -> m () Source #
Component view.
liftView :: t () -> m () Source #
Lift a monadic action into the view.
switchView :: t Bool -> (forall (x :: Type -> Type). MonadView t x => x ()) -> (forall (x :: Type -> Type). MonadView t x => x ()) -> m () Source #
Conditional view.
This will render the first view if the condition is True, otherwise the second.
listView :: (Typeable a, Eq a) => t [a] -> (a -> forall (x :: Type -> Type). MonadView t x => x ()) -> m () Source #
List view. This will render a view for each item in the list.
Instances
| MonadIO m => MonadView m (Build m) Source # | |
Defined in Concoct.View.Build Methods useState :: Typeable a => m a -> Build m (StateRef a) Source # useRef :: Typeable a => m a -> Build m (ViewRef a) Source # useEffect :: (Eq d, Typeable d) => m d -> (d -> m ()) -> Build m () Source # useOnUnmount :: m () -> Build m () Source # component :: (forall (x :: Type -> Type). MonadView m x => x ()) -> Build m () Source # liftView :: m () -> Build m () Source # switchView :: m Bool -> (forall (x :: Type -> Type). MonadView m x => x ()) -> (forall (x :: Type -> Type). MonadView m x => x ()) -> Build m () Source # listView :: (Typeable a, Eq a) => m [a] -> (a -> forall (x :: Type -> Type). MonadView m x => x ()) -> Build m () Source # | |
| MonadIO m => MonadView m (Rebuild m) Source # | |
Defined in Concoct.View.Rebuild Methods useState :: Typeable a => m a -> Rebuild m (StateRef a) Source # useRef :: Typeable a => m a -> Rebuild m (ViewRef a) Source # useEffect :: (Eq d, Typeable d) => m d -> (d -> m ()) -> Rebuild m () Source # useOnUnmount :: m () -> Rebuild m () Source # component :: (forall (x :: Type -> Type). MonadView m x => x ()) -> Rebuild m () Source # liftView :: m () -> Rebuild m () Source # switchView :: m Bool -> (forall (x :: Type -> Type). MonadView m x => x ()) -> (forall (x :: Type -> Type). MonadView m x => x ()) -> Rebuild m () Source # listView :: (Typeable a, Eq a) => m [a] -> (a -> forall (x :: Type -> Type). MonadView m x => x ()) -> Rebuild m () Source # | |
| MonadIO m => MonadView m (Skip m) Source # | |
Defined in Concoct.View.Skip Methods useState :: Typeable a => m a -> Skip m (StateRef a) Source # useRef :: Typeable a => m a -> Skip m (ViewRef a) Source # useEffect :: (Eq d, Typeable d) => m d -> (d -> m ()) -> Skip m () Source # useOnUnmount :: m () -> Skip m () Source # component :: (forall (x :: Type -> Type). MonadView m x => x ()) -> Skip m () Source # liftView :: m () -> Skip m () Source # switchView :: m Bool -> (forall (x :: Type -> Type). MonadView m x => x ()) -> (forall (x :: Type -> Type). MonadView m x => x ()) -> Skip m () Source # listView :: (Typeable a, Eq a) => m [a] -> (a -> forall (x :: Type -> Type). MonadView m x => x ()) -> Skip m () Source # | |
| MonadIO m => MonadView m (Unmount m) Source # | |
Defined in Concoct.View.Unmount Methods useState :: Typeable a => m a -> Unmount m (StateRef a) Source # useRef :: Typeable a => m a -> Unmount m (ViewRef a) Source # useEffect :: (Eq d, Typeable d) => m d -> (d -> m ()) -> Unmount m () Source # useOnUnmount :: m () -> Unmount m () Source # component :: (forall (x :: Type -> Type). MonadView m x => x ()) -> Unmount m () Source # liftView :: m () -> Unmount m () Source # switchView :: m Bool -> (forall (x :: Type -> Type). MonadView m x => x ()) -> (forall (x :: Type -> Type). MonadView m x => x ()) -> Unmount m () Source # listView :: (Typeable a, Eq a) => m [a] -> (a -> forall (x :: Type -> Type). MonadView m x => x ()) -> Unmount m () Source # | |
StateRef
State reference.
Created with useState.
readStateRef :: MonadIO m => StateRef a -> m a Source #
Read a state reference.
writeStateRef :: MonadIO m => StateRef a -> a -> m () Source #
Write to a state reference.
This will schedule an update to the current component.
ViewRef
readViewRef :: Applicative m => ViewRef a -> m a Source #
Read a view reference.
Stack
Constructors
| Stack | |
Fields
| |
emptyStack :: Stack Source #
flushStack :: Stack -> Stack Source #
ViewState
rebuildState :: forall (m :: Type -> Type) a. (MonadIO m, Typeable a) => StateT ViewState m (StateRef a) Source #