bramstein / knockout.selection

A selection binding for Knockout.js
19 stars 9 forks source link

EventMatcher - separate matching from calling the callback #82

Open mwoc opened 10 years ago

mwoc commented 10 years ago

knockout.selection behaves differently if there are zero items to select, it will then not call stopPropagation/preventDefault on events which it would have caught if there were items.

This causes Ctrl+A for example to select random content, while the desired behaviour would be that it in this case does nothing as there are no items.

To tackle this, it would be nice to alter the event handlers which we register, so they check if an event would match before checking if there is an item to call the callback with, and call stopPropagation/preventDefault for all matched events.

I propose modifying the EventMatcher, so that the EventMatcher.match method returns a callback, rather than calling it. The event handler can then call it with an item if there is one.

@bramstein @sunesimonsen @papandreou what's your opinions on that?

papandreou commented 10 years ago

Hmm, wouldn't that make EventMatcher a totally generic pattern matching module?

Sounds like we'd immediately build an abstraction on top of it that saves us from checking for the presence of an item in each callback -- in which case I'd rather change the EventMatcher into something that supports what we want to do.