Closed chekoopa closed 3 years ago
Hello @chekoopa
I am not against this, but I can see, for example, you finding out later that you need to handle more than just enter, or writing a bunch of onXPressed
functions.
That being said, I don't see any issues either with changing RawEvent
to return Maybe Message
(and consequently HE.createRawEvent
) instead of adding yet another create*Event
function.
Do you think you can provide a PR for this? Btw, what sort of things are you using flame for?
Hi again :relaxed:
I can see, for example, you finding out later that you need to handle more than just enter, or writing a bunch of
onXPressed
functions.
Sure thing, in case when you need more than one-two buttons, you put a onKeyup
and process it in update
. I'm talking about an amount of little cases such as submit-text-on-Enter or mouse dragging (I'm now working Elm's DnD library port, because it turns out we need reorderable lists :laughing:)
That being said, I don't see any issues either with changing
RawEvent
to returnMaybe Message
(and consequentlyHE.createRawEvent
) instead of adding yet anothercreate*Event
function.
Yes, I've thought about that it the first place, however it's an API-breaking change. If you're not against that (bumping a major version number), I can do. And as a code needed to implement this is pretty little, all I need is just to sit and code it.
Btw, what sort of things are you using flame for?
Flame is now becoming a part of our company's stack (besides of Haskell, NixOS and a little of Python) as a main frontend tool (actually, it's the third stop as for frontend tools, after Elm and Hedwig). We develop the educational interactive stand about intelligent energy systems, btw.
Yes, I've thought about that it the first place, however it's an API-breaking change. If you're not against that (bumping a major version number), I can do.
Yea, thats fine. I don't think anyone depends on that, anyway.
Flame is now becoming a part of our company's stack (besides of Haskell, NixOS and a little of Python) as a main frontend tool (actually, it's the third stop as for frontend tools, after Elm and Hedwig). We develop the educational interactive stand about intelligent energy systems, btw.
Interesting!
Now
handleRawEvent
underFlame.Renderer.toVNode
just calls handler and gives its result to updater function, so when you're writing event handlers you have to return message regardless of the event's content.For example, we would want to have a conditional event, like "on Enter key pressed", which now is implemented like this:
The only possible alternative is just using
onKeyup
and filtering the pressed key inupdate
function, but it mostly adds bloat in the application's logic (if you need to catch only one particular key). One could try throwing an error to break the event handling, but it also breakstoVNode
execution, too. Yes, we could just wrap handler intotry
, but it either prevents us from handling real errors or forces unpleasant trace messages in the console.Therefore, the proposal is to change event handler's type to
Event -> Effect (Maybe msg)
, so we could filter the event right in the handler. Also, it would look more consistent considering how EffectListupdate
function deals with events (usingAff (Maybe msg)
) and channel message types (eitherArray msg
orMaybe msg
).The updated example code would look like this:
The proposed changes wouldn't break existing API, as already placed event constructors only get an additional
Just
wrapper under the hood. But additionally, we'd get acreateRawEvent'
orcreateFilteredEvent
(the naming is a point of discussion).