Skip to content

Commit

Permalink
[Bugfix beta] if no view is found, we should not stop propagation as …
Browse files Browse the repository at this point in the history
…it is likely a virtual view or no longer present.

This interferes with using other libraries when they do want these events
  • Loading branch information
stefanpenner committed Jul 17, 2014
1 parent d7eb3be commit 187e77c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 6 additions & 8 deletions packages/ember-views/lib/system/event_dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ export default EmberObject.extend({
rootElement: 'body',

/**
It enables events to be dispatched to the view `eventManager` which object
when present takes precedence over events of the same name handled through methods
It enables events to be dispatched to the view `eventManager` which object
when present takes precedence over events of the same name handled through methods
on the view.
Most of the ember applications does not implement view `eventManagers`,
then disabling this property will provide some performance benefit
Most of the ember applications does not implement view `eventManagers`,
then disabling this property will provide some performance benefit
because it skips the search for the `eventManager` on the view tree.
```javascript
Expand All @@ -106,7 +106,7 @@ export default EmberObject.extend({
focusout : 'focusOut',
change : 'change'
},
canDispatchToEventManager: false
canDispatchToEventManager: false
});
container.register('event_dispatcher:main', EventDispatcher);
```
Expand Down Expand Up @@ -183,15 +183,13 @@ export default EmberObject.extend({
rootElement.on(event + '.ember', '.ember-view', function(evt, triggeringManager) {
var view = View.views[this.id],
result = true;

var manager = self.canDispatchToEventManager ? self._findNearestEventManager(view, eventName) : null;

if (manager && manager !== triggeringManager) {
result = self._dispatchEvent(manager, evt, eventName, view);
} else if (view) {
result = self._bubbleEvent(view, evt, eventName);
} else {
evt.stopPropagation();
}

return result;
Expand Down
10 changes: 6 additions & 4 deletions packages/ember-views/tests/system/event_dispatcher_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@ test("events should stop propagating if the view is destroyed", function() {
ok(!parentViewReceived, "parent view does not receive the event");
});

test("should not interfere with event propagation", function() {
test('should not interfere with event propagation of virtualViews', function() {
var receivedEvent;
view = View.create({

var view = View.create({
isVirtual: true,
render: function(buffer) {
buffer.push('<div id="propagate-test-div"></div>');
}
Expand All @@ -200,8 +202,8 @@ test("should not interfere with event propagation", function() {

jQuery('#propagate-test-div').click();

ok(receivedEvent, "allowed event to propagate outside Ember");
deepEqual(receivedEvent.target, jQuery('#propagate-test-div')[0], "target property is the element that was clicked");
ok(receivedEvent, 'allowed event to propagate');
deepEqual(receivedEvent && receivedEvent.target, jQuery('#propagate-test-div')[0], 'target property is the element that was clicked');
});

test("should dispatch events to nearest event manager", function() {
Expand Down

0 comments on commit 187e77c

Please sign in to comment.