Instawork / hyperview

Server-driven mobile apps with React Native
https://hyperview.org
MIT License
1.23k stars 57 forks source link

Trigger `change` is not working with action `dispatch-event` if there is no `delay` attribute #536

Open abdelav opened 1 year ago

abdelav commented 1 year ago

Using the a behavior change trigger to dispatch an event on <Text-field> element is not working if the behavior doesn't have the delay attribute.

Not working example:

<text-field name="phone" placeholder="Your phone number">
  <behavior trigger="change" action="dispatch-event" event-name="some-event" />
</text-field>

working example:

<text-field name="phone" placeholder="Your phone number">
  <behavior delay="0" trigger="change" action="dispatch-event" event-name="some-event" />
</text-field>
adamstep commented 1 year ago

Let me test this in the demo app, will report back.

adamstep commented 1 year ago

@abdelav did you notice this for other behavior actions, or only dispatch-event?

abdelav commented 1 year ago

I just tested with dispatch-event so far, but let me test with other actions an I will report back.

adamstep commented 1 year ago

I just tried it in the demo app and couldn't reproduce with dispatch-event: https://github.com/Instawork/hyperview/compare/adam/test-event1?expand=1

https://user-images.githubusercontent.com/1034502/236074739-509e3beb-7408-4720-b10a-f1467232d01f.mp4

abdelav commented 1 year ago

ok, this is probably an internal issue then?

adamstep commented 1 year ago

Perhaps, message me privately with the issue so we can check.

Poundex commented 1 month ago

Hello,

It looks like this might still be an issue. I have a <behavior /> with a trigger="change" and action="dispatch-event" which did not seem to be actually dispatching the event. After finding this issue and trying the delay="0" workaround it started working straight away (thanks, @abdelav !).

Here is some log output with the two scenarios:

With delay="0"

 INFO  [behavior] | action: set-value | ["<behavior trigger=\"change\" action=\"set-value\" target=\"zoomHotTub\" new-value=\" \" ran-once=\"true\" xmlns=\"h ttps://hyperview.org/hyperview\"/>"]
 INFO  [behavior] | action: dispatch-event | ["<behavior trigger=\"change\" action=\"dispatch-event\" event-name=\"refresh-zoom-form\" delay=\"0\" ran-once=\ "true\" xmlns=\"https://hyperview.org/hyperview\"/>"]
 INFO  [dispatch-event] action [refresh-zoom-form] emitted. []
 INFO  [behavior] | action: replace | ["<behavior trigger=\"on-event\" event-name=\"refresh-zoom-form\" action=\"replace\" href=\"/zoomcontrol\" verb=\"post\ " target=\"zoomform\" once=\"true\" ran-once=\"true\" xmlns=\"https://hyperview.org/hyperview\"/>"]
 INFO  [on-event] trigger [ ["refresh-zoom-form", "] caught by: ", "<behavior trigger=\"on-event\" event-name=\"refresh-zoom-form\" action=\"replace\" href=\ "/zoomcontrol\" verb=\"post\" target=\"zoomform\" once=\"true\" ran-once=\"true\" xmlns=\"https://hyperview.org/hyperview\"/>"]
 INFO  [dispatch-event] action [zoom-updated] emitted. []
 INFO  [behavior] | action: replace | ["<behavior trigger=\"on-event\" event-name=\"zoom-updated\" action=\"replace\" href=\"/zoombutton\" once=\"true\" ran- once=\"true\" xmlns=\"https://hyperview.org/hyperview\"/>"]
 INFO  [on-event] trigger [ ["zoom-updated", "] caught by: ", "<behavior trigger=\"on-event\" event-name=\"zoom-updated\" action=\"replace\" href=\"/zoombutt on\" once=\"true\" ran-once=\"true\" xmlns=\"https://hyperview.org/hyperview\"/>"]
 INFO  [behavior] | action: dispatch-event | ["<behavior trigger=\"load\" action=\"dispatch-event\" event-name=\"zoom-updated\" once=\"true\" ran-once=\"true \" xmlns=\"https://hyperview.org/hyperview\"/>"]

Without delay="0"

 INFO  [behavior] | action: set-value | ["<behavior trigger=\"change\" action=\"set-value\" target=\"zoomHotTub\" new-value=\" \" ran-once=\"true\" xmlns=\"h ttps://hyperview.org/hyperview\"/>"]
 INFO  [dispatch-event] action [refresh-zoom-form] emitted. []
 INFO  [behavior] | action: dispatch-event | ["<behavior trigger=\"change\" action=\"dispatch-event\" event-name=\"refresh-zoom-form\" ran-once=\"true\" xmln s=\"https://hyperview.org/hyperview\"/>"]

As you can see, the action: dispatch-event for the change event does appear in both logs, but the second is missing the expected [dispatch-event] action line