Skip to content

Commit

Permalink
issue #87: del() not cleaning up arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
chieffancypants committed Sep 15, 2014
1 parent 1e870b2 commit 6a0c218
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/hotkeys.js
Expand Up @@ -390,9 +390,10 @@

Mousetrap.unbind(combo);

if (combo instanceof Array) {
if (angular.isArray(combo)) {
var retStatus = true;
for (var i = 0; i < combo.length; i++) {
var i = combo.length;
while (i--) {
retStatus = _del(combo[i]) && retStatus;
}
return retStatus;
Expand Down
23 changes: 16 additions & 7 deletions test/hotkeys.coffee
Expand Up @@ -251,24 +251,33 @@ describe 'Angular Hotkeys', ->
it 'should be capable of binding to a scope and auto-destroy itself', ->
hotkeys.bindTo(scope)
.add
combo: 'w'
combo: ['w', 'e', 's']
description: 'description for w'
callback: () ->
persistent: false
.add
combo: 'e'
combo: 'a'
action: 'keyup'
description: 'description for e',
description: 'description for a',
callback: () ->
.add 's', 'description for s', () ->
.add('b', 'description for b', () ->)
.add('c', 'description for c', () ->)


expect(hotkeys.get('w').combo).toEqual ['w', 'e', 's']
expect(hotkeys.get('e').combo).toEqual ['w', 'e', 's']
expect(hotkeys.get('a').combo).toEqual ['a']
expect(hotkeys.get('b').combo).toEqual ['b']
expect(hotkeys.get('c').combo).toEqual ['c']

expect(hotkeys.get('w').combo).toEqual ['w']
expect(hotkeys.get('e').combo).toEqual ['e']
expect(hotkeys.get('s').combo).toEqual ['s']
scope.$destroy()
expect(hotkeys.get('w')).toBe false
expect(hotkeys.get('e')).toBe false
expect(hotkeys.get('s')).toBe false
expect(hotkeys.get('a')).toBe false
expect(hotkeys.get('b')).toBe false
expect(hotkeys.get('c')).toBe false


describe 'misc regression tests', ->

Expand Down

0 comments on commit 6a0c218

Please sign in to comment.