clientside / amplesdk

Ample SDK - JavaScript UI Framework
Other
170 stars 29 forks source link

Binding Multiple Events with One "bind" Like in JQuery API #164

Closed amoilanen closed 11 years ago

amoilanen commented 11 years ago

JQuery allows to bind a handler to a few events at once, please, see http://api.jquery.com/bind/ "Multiple Events".

I think the support can be added for binding multiple events to the Ample API similar to JQuery functionality.

For example, the following should bind handlers both to the "focus" and "blur" events:


ample.bind("focus blur", function (event) {
    ...
});

ample.query(cssSelector).bind("focus blur", function (event) {
    ...
});

While I understand that it is not a goal to include complicated custom APIs into Ample SDK but rather make existing ones work well and be extensible, still this addition may be a nice syntactic sugar. Also the described behavior is something that I would personally expect from the API.

Also I would expect for "ample.bind()" to return "ample" and not "undefined" so that we can chain invocations together like with "ample.query(cssSelector).bind()".

The only concern that I have is backward compatibility: the old code may be broken with this API update if it used events with blanks in the event name. But using event names with blanks in them would be very strange to begin with.

ilinsky commented 11 years ago

Fixed per rev 5bb3c298f21e4cb83fb83e1a6ab7471c7a05792c