glazier-react-1.0.0.0: ReactJS binding using Glazier.Command.

Safe HaskellNone
LanguageHaskell2010

Glazier.React.Reactor

Synopsis

Documentation

type AsReactor cmd = (AsFacet [cmd] cmd, AsFacet (ReactorCmd cmd) cmd) Source #

type MonadReactor p s cmd m = (AsReactor cmd, MonadReader (Entity p s) m, MonadCommand cmd m) Source #

data ReactorCmd cmd where Source #

NB. ReactorCmd is not a functor because of the Widget cmd in MkSubject

Constructors

MkReactId :: JSString -> (ReactId -> cmd) -> ReactorCmd cmd

Make a unique named id

SetRender :: Subject s -> Window s () -> ReactorCmd cmd

the the rendering function in a Subject, replace any existing render callback

MkSubject :: Widget cmd s s () -> s -> (Subject s -> cmd) -> ReactorCmd cmd

Make a fully initialized subject (with ShimCallbacks) from a widget spec and state

BookSubjectCleanup :: Subject s -> ReactorCmd cmd

Keep subject alive until the next rerender

GetModel :: Subject s -> (s -> cmd) -> ReactorCmd cmd

Generate a list of commands from reading the model.

GetElementalRef :: Subject s -> ReactId -> (EventTarget -> cmd) -> ReactorCmd cmd 
Rerender :: Subject s -> ReactorCmd cmd

Rerender a ShimComponent using the given state.

TickModel :: Subject s -> ModelState s cmd -> ReactorCmd cmd

Update and rerender.

RegisterDOMListener :: NFData a => Subject s -> JSRep -> JSString -> (JSRep -> MaybeT IO a) -> (a -> cmd) -> ReactorCmd cmd

Create and register a dom callback

RegisterReactListener :: NFData a => Subject s -> ReactId -> JSString -> (JSRep -> MaybeT IO a) -> (a -> cmd) -> ReactorCmd cmd

Create and register a react callback If the callback is for "ref", then an listener to update elementalRef for GetEventTarget will automatically be added just before the listener in RegisterReactListener.

RegisterMountedListener :: Subject s -> cmd -> ReactorCmd cmd

Create and register a callback for the mounted event

RegisterRenderedListener :: Subject s -> cmd -> ReactorCmd cmd

Create and register a callback for the rendered event

RegisterNextRenderedListener :: Subject s -> cmd -> ReactorCmd cmd

Create and register a callback for the rendered event

RegisterTickedListener :: Subject s -> cmd -> ReactorCmd cmd

Create and register a callback for the state updated event

Instances
Show (ReactorCmd cmd) Source # 
Instance details

Defined in Glazier.React.Reactor

Methods

showsPrec :: Int -> ReactorCmd cmd -> ShowS #

show :: ReactorCmd cmd -> String #

showList :: [ReactorCmd cmd] -> ShowS #

mkReactId :: (AsReactor cmd, MonadCommand cmd m) => JSString -> m ReactId Source #

Make a unique named id

setRender :: (AsReactor cmd, MonadCommand cmd m) => Subject s -> Window s () -> m () Source #

mkSubject :: (AsReactor cmd, MonadCommand cmd m) => Widget cmd s s a -> s -> m (Either a (Subject s)) Source #

Make an initialized Subject for a given model using the given Widget.

mkSubject' :: (AsReactor cmd, MonadCommand cmd m) => Widget cmd s s () -> s -> m (Subject s) Source #

Make an initialized Subject for a given model using the given Widget.

withMkSubject :: (AsReactor cmd, MonadCommand cmd m) => Widget cmd s s a -> s -> (Subject s -> m ()) -> m a Source #

Make an initialized Subject for a given model using the given Widget.

bookSubjectCleanup :: MonadReactor p allS cmd m => Subject s -> m () Source #

Schedule cleanup of the callbacks when the parent widget is rerendered.

getModel :: MonadReactor p s cmd m => m s Source #

Get the Model and exec actions, using the current Entity context

getElementalRef :: MonadReactor p s cmd m => ReactId -> m EventTarget Source #

Get the event target If a "ref" callback to update elementalRef has not been added; then add it, rerender, then return the EventTarget.

rerender :: MonadReactor p s cmd m => m () Source #

Rerender the ShimComponent using the current Entity context

tickModel :: MonadReactor p s cmd m => ModelState s () -> m () Source #

Update the Model using the current Entity context

tickModelThen :: (Also m a, MonadReactor p s cmd m) => ModelState s (m a) -> m a Source #

Update the Scene using the current Entity context, and also return the next action to execute.

domTrigger :: (NFData a, MonadReactor p s cmd m) => JSRep -> JSString -> (JSRep -> MaybeT IO a) -> m a Source #

Create a callback for a JSRep and add it to this elementals's dlist of listeners.

domTrigger_ :: MonadReactor p s cmd m => JSRep -> JSString -> a -> m a Source #

A variation of trigger which ignores the event but fires the given arg instead.

trigger :: (NFData a, MonadReactor p s cmd m) => ReactId -> JSString -> (Notice -> MaybeT IO a) -> m a Source #

Create a callback for a Notice and add it to this elementals's dlist of listeners.

trigger_ :: MonadReactor p s cmd m => ReactId -> JSString -> a -> m a Source #

A variation of trigger which ignores the event but fires the given arg instead.

onMounted :: MonadReactor p s cmd m => m a -> m a Source #

Register actions to execute after a render. It is safe to postCmd' a TickScene or Rerender. These command will not trigger another rendered event.

NB. This is trigged by react componentDidMount See jsbits/react.js hgr$shimComponent. These callbacks are called after the ref callback by React See https://reactjs.org/docs/refs-and-the-dom.html.

onRendered :: MonadReactor p s cmd m => m a -> m a Source #

Register actions to execute after a render. It is safe to postCmd' a TickScene or Rerender. These command will not trigger another rendered event.

NB. This is trigged by react componentDidUpdate and componentDidMount so it is also called for the initial render. See jsbits/react.js hgr$shimComponent. These callbacks are called after the ref callback by React See https://reactjs.org/docs/refs-and-the-dom.html.

onNextRendered :: MonadReactor p s cmd m => m a -> m a Source #

onTicked :: MonadReactor p s cmd m => m a -> m a Source #

Register actions to execute after the state has been updated with TickState. It is safe to postCmd' another TickScene, another onRendered event will not be generated.

NB. This is trigged by react componentDidUpdate and componentDidMount so it is also called for the initial render. See jsbits/react.js hgr$shimComponent. These callbacks are called after the ref callback by React See https://reactjs.org/docs/refs-and-the-dom.html.