<commit_before>{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Ohm.Component
  (
    Processor(..)
  , Component(..)
  , appModel
  , runComponent
  ) where

import Control.Monad.Trans.Reader
import Control.Monad.State
import MVC
import HTML (Renderer, domChannel, newTopLevelContainer, renderTo)

newtype Processor edom ein m = Processor
  { 
    runProcessor :: edom -> Producer ein m ()
  } deriving (Monoid)

data Component env ein model edom = Component {
   
    -- | The processing function of a 'Model' for this component
    model :: ein -> model -> model
    
    -- | A renderer for 'Model' creating 'HTML' produces 'DOMEvent's
  , render :: Renderer edom model
  
    -- | A processor of events emitted from the UI
    --
    -- This has the choice of feeding events back into the model
  , domEventsProcessor :: Processor edom ein (ReaderT env IO)
  }

appModel :: (e -> m -> m) ->  Model m e m
appModel fn = asPipe $ forever $ do
  m <- await
  w <- lift $ get
  let w' = fn m w
  lift $ put w'<commit_msg>Missed an import: HTML -> Ohm.HTML<commit_after>{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Ohm.Component
  (
    Processor(..)
  , Component(..)
  , appModel
  , runComponent
  ) where

import Control.Monad.Trans.Reader
import Control.Monad.State
import MVC
import Ohm.HTML (Renderer, domChannel, newTopLevelContainer, renderTo)

newtype Processor edom ein m = Processor
  { 
    runProcessor :: edom -> Producer ein m ()
  } deriving (Monoid)

data Component env ein model edom = Component {
   
    -- | The processing function of a 'Model' for this component
    model :: ein -> model -> model
    
    -- | A renderer for 'Model' creating 'HTML' produces 'DOMEvent's
  , render :: Renderer edom model
  
    -- | A processor of events emitted from the UI
    --
    -- This has the choice of feeding events back into the model
  , domEventsProcessor :: Processor edom ein (ReaderT env IO)
  }

appModel :: (e -> m -> m) ->  Model m e m
appModel fn = asPipe $ forever $ do
  m <- await
  w <- lift $ get
  let w' = fn m w
  lift $ put w'
{'fraction_non_alphanumeric': 0.11149081589064502, 'fraction_numerical': 0.0, 'mean_word_length': 2.9361344537815124, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3265955', 'n_tokens_mistral': 778, 'n_tokens_neox': 755, 'n_words': 257}