mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Rename App.coffee to Atom.coffee. This also required moving src/atom,spec/atom to src/app,spec/app
This commit is contained in:
25
src/app/binding-set.coffee
Normal file
25
src/app/binding-set.coffee
Normal file
@@ -0,0 +1,25 @@
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
Specificity = require 'specificity'
|
||||
|
||||
module.exports =
|
||||
class BindingSet
|
||||
selector: null
|
||||
commandForEvent: null
|
||||
|
||||
constructor: (@selector, mapOrFunction) ->
|
||||
@specificity = Specificity(@selector)
|
||||
@commandForEvent = @buildEventHandler(mapOrFunction)
|
||||
|
||||
buildEventHandler: (mapOrFunction) ->
|
||||
if _.isFunction(mapOrFunction)
|
||||
mapOrFunction
|
||||
else
|
||||
(event) =>
|
||||
for pattern, command of mapOrFunction
|
||||
return command if @eventMatchesPattern(event, pattern)
|
||||
null
|
||||
|
||||
eventMatchesPattern: (event, pattern) ->
|
||||
pattern = pattern.replace(/^<|>$/g, '')
|
||||
event.keystroke == pattern
|
||||
Reference in New Issue
Block a user