pteasima / VTree

VirtualDOM for Swift (iOS, macOS)
MIT License
0 stars 0 forks source link

Combine handlers and gestures into one #4

Open pteasima opened 6 years ago

pteasima commented 6 years ago

I feel like there is no fundamental difference between handlers and gestures, as well other callbacks we might want to have (like viewDidAppear or void delegate callbacks). Elm solves this using Html.Attributes. The reason elm combines all events, layout and styles into one array attributes is because are actually all just that - html attributes. There are actually good reasons to separate them (e.g. elm-style-elements separates Style and other Attributes). Thus, the decision to separate VTree’s styles, flexbox and others is not in principle a bad one. For example its nice to realize that by supplying a flexbox parametr, you are overriding the behaviour of the frame style (this might not be the case and certainly wouldnt be obvious if these were passed in one array with arbitrary order). However, I dont see any such reason for separating events into gestures, handlers and possibly more. While this makes the internal implementation of things like Apply.swift simpler, I believe it isnt nice for the public API. Ideally, we would provide a public API which expects an array of Events, and functions to create these. These would translate internally to instances of an enum Internal.Event with cases like .gesture, .cocoaAction, .delegateCallback. I have to think about what impact this would have on the magic the VTree does with sourcery code generation, but it should be fine.

The main motivation behund this is to reduce the size of the VTree protocol. I dont think it worth it now but should be done when we add more events other than handlers and gestures.

In Elm, you can pass an onInput handler to a non-interactive text element and it just does nothing. Web people tend not to care about stuff like this. I think we could still come up with a way to indicate that, for example, only a node representing a UITableView can specify UITableViewDelegate callbacks. This is not a priority but should be thought about when implementing this task (it might turn out that its not worth it and keeping each type of event separate is the best thing to do).

pteasima commented 6 years ago

Might be related to inamiy/VTree#7