module Chiasma.Data.View where

import Chiasma.Data.Ident (Ident, Identifiable(..))
import Control.Lens (makeClassy_)
import qualified Control.Lens as Lens (set)

data View a =
  View {
    View a -> Ident
viewIdent :: Ident,
    View a -> Maybe a
viewId :: Maybe a
  }
  deriving (View a -> View a -> Bool
(View a -> View a -> Bool)
-> (View a -> View a -> Bool) -> Eq (View a)
forall a. Eq a => View a -> View a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: View a -> View a -> Bool
$c/= :: forall a. Eq a => View a -> View a -> Bool
== :: View a -> View a -> Bool
$c== :: forall a. Eq a => View a -> View a -> Bool
Eq, Int -> View a -> ShowS
[View a] -> ShowS
View a -> String
(Int -> View a -> ShowS)
-> (View a -> String) -> ([View a] -> ShowS) -> Show (View a)
forall a. Show a => Int -> View a -> ShowS
forall a. Show a => [View a] -> ShowS
forall a. Show a => View a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [View a] -> ShowS
$cshowList :: forall a. Show a => [View a] -> ShowS
show :: View a -> String
$cshow :: forall a. Show a => View a -> String
showsPrec :: Int -> View a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> View a -> ShowS
Show)

makeClassy_ ''View

instance Identifiable (View a) where
  identify :: View a -> Ident
identify = View a -> Ident
forall a. View a -> Ident
viewIdent

setViewId :: a -> View a -> View a
setViewId :: a -> View a -> View a
setViewId =
  ASetter (View a) (View a) (Maybe a) (Maybe a)
-> Maybe a -> View a -> View a
forall s t a b. ASetter s t a b -> b -> s -> t
Lens.set ASetter (View a) (View a) (Maybe a) (Maybe a)
forall c a. HasView c a => Lens' c (Maybe a)
_viewId (Maybe a -> View a -> View a)
-> (a -> Maybe a) -> a -> View a -> View a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe a
forall a. a -> Maybe a
Just