Feature: add element dependency with events#81
Merged
Conversation
Contributor
|
for debugging:
|
Contributor
|
Contributor
Author
|
Thanks for the feedback @adamstep, I've added support for |
flochtililoch
approved these changes
Jul 25, 2019
Collaborator
flochtililoch
left a comment
There was a problem hiding this comment.
Looks good to me, thanks for implementing this!
This was referenced Jul 31, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference
Spec
This feature introduces a new trigger -
on-eventand a new behavior actiondispatch-event. (Refer to the example for complete XML)Consider the following
viewrendered on the screen:This
viewwill listen foron-eventtrigger specifically for theevent-nametest-event(throws an error ifevent-nameis not specified). When this event is caught, it does theappendaction and appends the XML fragmentdispatch_event_append.xmlwhich looks like:The source of this event is a different screen:
With the
presstrigger thedispatch-eventaction will fire an event (internal to hyperview) with the name defined by theevent-nameattribute (if not provided throws an error).Overview
This uses an event emitter (or pub-sub) based approach for implementation. I went with this approach since the hyperview screens could be different for different routes (and navigators). The alternative approach which I didn't go with was to use the context API due to following reasons:
An event emitter based approach looked better and simpler to me. I also tried to look into options if I could build this on top of
react-navigationwith some shared event publishers and subscribers but didn't spend much time on it since I wasn't able to find something related on the topic which I could use.Also supports
onceanddelay:oncebehavior(withtrigger="on-event"), the behavior would only respond to the dispatched event once (till the screen is unmounted)behavior(withaction="dispatch-event"), the behavior will only dispatch the event oncedelaybehavior(withtrigger="on-event"), the behavior would respond to the dispatched event after the specified delay. (Note that when the delay is large this can lead to indeterminate UI state related)behavior(withaction="dispatch-event"), the behavior will dispatch the event after the specified delayToDo
trigger="on-event"andaction="dispatch-event"and throw an error or warning?__DEV__mode?trigger="on-event"andaction="dispatch-event"should be help with this but any better ideas?Any other feedback? Would love some help with testing it for more actions/triggers in case there are any issues.
Demo
The following demos use the same example mentioned in the spec above. A screen is able to trigger an append in a different screen using the event dispatch system.
prependactionappendactionDebugging
Next steps