-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for life cycle events #16
Comments
Hi Bas, you highlight an interesting problem. I currently do not have an Best regards,
|
Hi @basvandijk, I don't know whether this would be harder to implement, but from an API point of view it seems like it would be best to expose this via a request. domNodeRequest
:: (DomNode -> act)
-- ^ A wrapper for the node info
-> String
-- ^ The ID of the element you're looking for
-> IO act Say you need the DOM info for element "#foo". When you move into a state which includes "#foo" in its view, you submit a By the way, in blaze-react-0.2, you would implement this as a service: module Blaze.Core.Service.DomNode
( DomNodeR(..)
, DomNodeA(..)
) where
newtype DomNodeR = GetNodeInfo String
newtype DomNodeA = ReturnNodeInfo DomNode module Blaze.ReactJS.Service.DomNode
( handleRequest
) where
handleRequest :: (DomNodeA -> IO ()) -> DomNodeR -> IO ()
handleRequest channel request = ... |
In our app we need to know the dimensions of a specific HTML node after it's inserted into the native DOM. React provides Life Cycle Methods (specifically the
componentDidUpdate
) to support this.In LumiGuide@bf9a35e @roelvandijk and I made an initial implementation for this.
We don't think we have the right design yet but at the moment it works for us. So see this as a way to start the design discussion.
API
DomNode
is a partial representation of the actual DOM node that was updated:I'm not sure this representation is ideal since we are deciding for the user which properties of the actual DOM node we put in
DomNode
. It might be better to have:so that the user can query (and manipulate!) the actual DOM node. This querying and manipulation does have to be performed in IO so users are required to use
tell [...]
for this.onDomDidUpdate
causes anotheronDomDidUpdate
to fire. This causes an infinite loop. To solve this we would like the user to have control over when the virtual DOM gets updated. For this we added theshouldUpdateDom
transition function:This directly corresponds to shouldComponentUpdate.
When the user calls:
shouldUpdateDom False
in his transition (and isn't followed by ashouldUpdateDom True
) the virtual DOM won't get updated.Implementation
When the user calls
onDomDidUpdate
like:someNode
will gain the attributedata-life-cycle-id=<fresh life-cycle id>
and we remember the "<fresh life-cycle id>
->handler
" association. This happens in Text.Blaze.Renderer.ReactJS.When we receive an update event for the root
blaze-react
component we loop over all the "life-cycle id
->handler
" associations, lookup the DOM node with the corresponding life-cycle id, construct aDomNode
and apply thehandler
to it.Since
blaze-react
is using a single component to represent the entire app it means that this component will receive all update events. It would be better to give the user access to the component API so that he can control the depth of each component.We modified
TransitionM
to be:The
Last Bool
records the desiredshouldUpdateDom
behavior.We went with a nested
WriterT
implementation instead of a singleWriterT
layer with a tuple so that we didn't need to modify existing calls totell
in client code (we have quite a few of them).The text was updated successfully, but these errors were encountered: