Skip to content

Commit

Permalink
Remove event proxying from core
Browse files Browse the repository at this point in the history
Fix #332.
  • Loading branch information
Tom Ashworth committed Jan 29, 2015
1 parent e69981a commit 1f3203d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 66 deletions.
23 changes: 0 additions & 23 deletions doc/base_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,29 +170,6 @@ this.after('initialize', function() {
});
```

Example of `handler` being a string that maps events to other events. This is
useful for proxying browser events to more meaningful custom events.

```js
this.on('click', 'uiComponentClick');
```

Example of `handler` being an object that maps events to other events.

```js
this.attributes({
menuItemSelector: '.menuItem',
saveButtonSelector: '#save'
});

this.after('initialize', function() {
this.on('click', {
menuItemSelector: 'uiMenuItemClick',
saveButtonSelector: 'uiSaveButtonClick'
});
});
```

<a name="this.off"></a>
## this.off([selector,] eventType [, handler])

Expand Down
10 changes: 1 addition & 9 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ define(
}, this);
}

function proxyEventTo(targetEvent) {
return function(e, data) {
$(e.target).trigger(targetEvent, data);
};
}

function withBase() {

// delegate trigger, bind and unbind to an element
Expand Down Expand Up @@ -174,8 +168,6 @@ define(
originalCb = utils.delegate(
this.resolveDelegateRules(origin)
);
} else if (typeof origin == 'string') {
originalCb = proxyEventTo(origin);
} else {
originalCb = origin;
}
Expand Down Expand Up @@ -255,7 +247,7 @@ define(
if (!(r in this.attr)) {
throw new Error('Component "' + this.toString() + '" wants to listen on "' + r + '" but no such attribute was defined.');
}
rules[this.attr[r]] = (typeof ruleInfo[r] == 'string') ? proxyEventTo(ruleInfo[r]) : ruleInfo[r];
rules[this.attr[r]] = ruleInfo[r];
}, this);

return rules;
Expand Down
34 changes: 0 additions & 34 deletions test/spec/events_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,40 +101,6 @@ define(['lib/component', 'lib/registry'], function (defineComponent, registry) {
expect(spy2).toHaveBeenCalled();
});

it('proxy from one to another when declared using "on" with a string', function () {
var instance = (new Component).initialize(window.outerDiv);
var data = {actor: 'Brent Spiner'};

// Declare an event proxy from 'sourceEvent' → 'targetEvent'
instance.on('sourceEvent', 'targetEvent');

var spy = jasmine.createSpy();
instance.on('targetEvent', spy);

instance.trigger('sourceEvent', data);

expect(spy).toHaveBeenCalled();
expect(spy.mostRecentCall.args[1]).toEqual(data);
});

it('proxy from one to another when declared using "on" with an object', function () {
var instance = (new Component).initialize(window.outerDiv, {'innerDiv': 'div'});
var data = {actor: 'Brent Spiner'};

// Declare an event proxy from 'sourceEvent' → 'targetEvent'
instance.on('sourceEvent', {
'innerDiv': 'targetEvent'
});

var spy = jasmine.createSpy();
instance.on(window.innerDiv, 'targetEvent', spy);

instance.trigger(window.innerDiv, 'sourceEvent', data);

expect(spy).toHaveBeenCalled();
expect(spy.mostRecentCall.args[1]).toEqual(data);
});

it('unbinds listeners using "off"', function () {
var instance1 = (new Component).initialize(window.outerDiv);

Expand Down

0 comments on commit 1f3203d

Please sign in to comment.