Closed Mouvedia closed 11 years ago
I'd do it this way:
on: @click { ... }
//which is equivalent to
on: @event { type: "click"; ... }
//or
on: @mouseUp { ... }
//equivalent to
on: @event { type: "mouseUp"; ... }
//etc
This has the advantage that we could accept custom event names inside @event's type property. Also, to use various events types at the same time:
on: @event { type: "mouseUp", "touchEnd"; ... }
Let's iterate on that then.
//events for the mouse
@event { type: mouseUp | mouseDown | mouseOver | mouseOut | mouseMove | mouseEnter | mouseLeave, …; }
//equivalent to
@mouseUp
@mouseDown
etc
Being able to use the object more directly is a good thing so +1.
Why not have 1:1 equivalents in the names? That seems counterintuitive. > corrected.
Also, you completely ignored my point on using strings, so we can accept custom event types too.
I think we should replace @event
by @mouse
so it would look a bit like that:
//events for the mouse
@mouse { type: "up" | "down" | "move" | "over" | "out" | "enter" | "leave", …; }
//equivalent to
@mouseUp
@mouseDown
@mouseMove
etc
That's much simpler for the user when he's using the long form (with type).
Concerning custom events we can't have them since it would require to have all the existing events as reserved names and hence could break if a custom one collides with a newly introduced one which didn't exist back then. Unless we accept custom ones as strings and system ones as keywords.
For completeness here's what it would look like for all input events:
@mouse { type: "up" | "down" | "move" | "over" | "out" | "enter" | "leave", …; }
//equivalent to
@mouseUp
@mouseDown
@mouseMove
@mouseOver
@mouseOut
@mouseEnter
@mouseLeave
//wouldn't have a type under @mouse (use @event)
@click
@doubleClick
@key { type: "up" | "down" | "press", …; }
//equivalent to
@keyUp
@keyDown
@keyPress
@touch { type: "start" | "end" | "enter" | "leave" | "move" | "hold", …; }
//equivalent to
@touchStart
@touchEnd
@touchEnter
@touchLeave
@touchMove
@touchHold
@event
@click
@doubleClick
@key
@keyUp
@keyDown
@keyPress
@mouse
@mouseUp
@mouseDown
@mouseMove
@mouseOver
@mouseOut
@mouseEnter
@mouseLeave
@touch
@touchStart
@touchEnd
@touchEnter
@touchLeave
@touchMove
@touchHold
Which means that all of these are types of @event
(since they descend from it) hence it also permits to do what you said earlier:
on: @event { type: "mouseUp", "touchEnd"; … }
*bubbles