{-| Description : Declarative handlers for page events (usually not necessary unless you're making an alternative to the 'Myxine.Reactive' builder) In order to react to user events in the browser, we need to specify what effect each event of interest should have on the model in our 'Myxine.Page'. To do this, 'Myxine.runPage' asks that we construct up-front a set of 'Handlers' describing this. 'Handlers' is a 'Monoid': the 'mempty' 'Handlers' listens to no events. Singleton 'Handlers' can be created using the 'onEvent' function, and they can be joined together using '<>'. This module is useful when you are building your own page event handling abstraction, for instance, if 'Myxine.Reactive' isn't right for your purposes. However, it is not necessary to use this module directly if you are building a reactive page using that high-level abstraction. -} module Myxine.Handlers ( Handlers , onEvent , handle , handledEvents , focusHandlers , TargetFact , tagIs , attrIs , window , Propagation(..) ) where import Data.Maybe import qualified Data.Text as Text import Data.Text (Text) import Data.Dependent.Map (DMap) import qualified Data.Dependent.Map as DMap import Control.Lens import Control.Monad.State import Myxine.Event import Myxine.Direct import Myxine.Target import Myxine.ConjMap (ConjMap) import qualified Myxine.ConjMap as ConjMap -- | Create a handler for a specific event type by specifying the type of event -- and the monadic callback to be invoked when the event occurs. -- -- The provided callback will be given the properties @props@ of this particular -- event, and the current @model@ of a page. It has the option to do arbitrary -- 'IO', and to return a possibly-changed @model@. It also must specify whether -- or not the event should continue to propagate outwards to other handlers, by -- giving a 'Propagation' (either 'Bubble' or 'Stop'). -- -- The callback will only be invoked when an event occurs which matches the -- conjunction of the specified list of 'TargetFact's. For instance, to -- constrain a handler to only events on @