{-# OPTIONS -fcontext-stack=22 -fglasgow-exts -fth -fallow-undecidable-instances #-} -- -# LANGUAGE FlexibleInstances, TemplateHaskell, UndecidableInstances #-} module State where import Types -- import HAppS import Data.Maybe import Data.Monoid import Control.Monad import qualified State.State_000 as Old import MyEntries as MyEntries import HAppS.Store.FlashMsgs import HAppS.Store.HelpReqs import HAppS.Data import HAppS.Server.State import HAppS.State import Control.Monad.Reader $(deriveAll [''Read,''Show,''Default] --TemplateHaskell to derive these classes [d| data StateKey = StateKey data State = State { myEntries :: Component MyEntries , flashMsgs :: Component (FlashMsgs [Element]) , helpReqs :: Component HelpReqs } |] ) instance StartState StateKey where startState = return StateKey {- instance SystemComponent FlashMsg' where componentHandlers get upd = getSubHandlers get upd (\(FlashMsg' flash) -> flash) (\flash _ -> FlashMsg' flash) -} --instance SystemComponent HelpReqs' where -- componentHandlers get upd = getSubHandlers get upd (\(HelpReqs' help) -> Component help) (\(Component help) _ -> HelpReqs' help) {-- Migrations When you change the version of a type, you rename file with that type to something else. Old is the name of the module with the prior version of State. --} instance Migrate Old.State State where migrate (Old.State ) = error "This is the first actual state" instance Xml State where version _ = Just "001" -- update this when you need to otherVersion _ = Other (error "Other" :: Old.State) --The below should be consolidated into a single command by someone.... -- $(makeState ''State $ ['myEntries,'flashMsgs,'helpReqs]) $(methods_ SerializeString ''State []) $(atStart ''State []) {-- $(inferRecordUpdaters ''State) $(inferStartState ''State) instance IsState State where getInterface _ = HelpReqs.commands ++ FlashMsgs.commands ++ MyEntries.commands instance HasFlashMsgs State where withFlashMsgs = State.withFlashMsgs flashMsgs = State.flashMsgs instance HasHelpReqs State where withHelpReqs = State.withHelpReqs helpReqs = State.helpReqs instance HasMyEntries State where withMyEntries = State.withMyEntries myEntries = State.myEntries --}