concoct-0.1.0: A declarative UI framework
Copyright(c) Matt Hunzinger 2026
LicenseBSD-style (see the LICENSE file in the distribution)
Maintainermatt@hunzinger.me
Stabilityprovisional
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

Concoct.View

Description

 
Synopsis

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

Instances details
MonadIO m => MonadView m (Build m) Source # 
Instance details

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 # 
Instance details

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 # 
Instance details

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 # 
Instance details

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

data StateRef a Source #

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

data ViewRef a Source #

View reference. Created with useRef.

readViewRef :: Applicative m => ViewRef a -> m a Source #

Read a view reference.

ViewTree

data ViewTree (t :: Type -> Type) Source #

View tree.

viewTree :: MonadIO t => (forall (m :: Type -> Type). MonadView t m => m ()) -> t (ViewTree t) Source #

Create a view tree from a view.

rebuildViewTree :: MonadIO t => ViewTree t -> t (ViewTree t) Source #

Rebuild the view tree if changed.

unmountViewTree :: MonadIO t => ViewTree t -> t (ViewTree t) Source #

Unmount the view tree.