axr / specification

This is where we work on the specification for AXR
spec.axrproject.org
13 stars 0 forks source link

input events #88

Closed Mouvedia closed 11 years ago

Mouvedia commented 11 years ago
on: @mouse
    {
          type: down | up | move | over* | out* | enter | leave, …;
          action:;
    }

*bubbles

veosotano commented 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"; ... }
Mouvedia commented 11 years ago

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.

veosotano commented 11 years ago

Why not have 1:1 equivalents in the names? That seems counterintuitive. > corrected.

veosotano commented 11 years ago

Also, you completely ignored my point on using strings, so we can accept custom event types too.

Mouvedia commented 11 years ago

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.

Mouvedia commented 11 years ago

For completeness here's what it would look like for all input events:

Mouse

@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

Keyboard

@key { type: "up" | "down" | "press", …; }
//equivalent to
@keyUp
@keyDown
@keyPress

Touch

@touch { type: "start" | "end" | "enter" | "leave" | "move" | "hold", …; }
//equivalent to
@touchStart
@touchEnd
@touchEnter
@touchLeave
@touchMove
@touchHold

Hierarchy

@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"; … }
Mouvedia commented 11 years ago

http://hss.axrproject.org/@event