-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Using newEventsNamed #49
Comments
Your definition looks fine to me, though the use of
The only advantage of At the moment, Could you elaborate on your use case? What do you mean by "event-based getters"? |
The idea is that you fire a request event and listen to a reply from a widget with the relevant value. The tags are needed to have multiple request/reply pairs which do not interfere with each other (as if they were calls to a getter done from different methods in an OOP context). For an example, I implemented them for my embryonic bounded input widget (look for the |
Ah, I see. In this case, there is no need for Also, I'm not entirely sure whether your implementation of event-based getters is a good idea in the first place. There are essentially two ways to work with Behaviors: use the Applicative combinators to combine them, or sample them with an Event. If I understand that correctly, your intention with event-based getters is to restrict yourself to the latter method, in which case it is convient to simply use a partial application of the sampling process. In code: The standard way to deal with values would be
For some reason, you don't want that, so the next best thing would be to offer a function
which tags a given event ("request a value") with the value of the behavior ("respond with the value"). There is no need for tags at all. Moreover, this formulation has the advantage that the request event and the response event are simultaneous. (Otherwise, there is a delay if you route them through an event firing.) That said, I don't quite understand why would wouldn't want a Behavior in the first place either. I can sort of understand it, though, because in my experience, it is a good idea to make UI elements only return user events. See a blog post of mine on this matter. |
Heh, (*) In the way it is done now, a request triggers validation; so if the user has, for instance, typed a value above the allowed maximum and there is a request then the returned value should be the maximum and the widget should be updated accordingly. Validating on blur might seem a more sensible thing to do, but it does not cover all relevant situations (e.g. suppose the request was triggered by a keyboard shortcut). |
On noticing
newEventsNamed
, my first thought was "here is a drop-in replacement forControl.Event.newEventsTagged
". The second thought, of course, was "but how do I fire the events"? Eventually, I understood thatnewEventsNamed
should be the way it is; partly by finding its uses in the rest of Threepenny, and partly from trying to make it equivalent to the oldnewEventsTagged
only to realize it is not as simple as it seems. On the other hand, it is easy to implement newEventsTagged using only the exported functions ofReactive.Threepenny
, and it works perfectly well (I use it to create event-based getters without having to expose the correspondingBehavior
). Given all of that, I am left with two questions: Is that a sensible use ofnewEventsNamed
? And do you see a place for something in the vein ofnewEventsTagged
in the API?The text was updated successfully, but these errors were encountered: