Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c0c5d8e

Browse files
author
Simon Tsvilik
committed
fix(rootScope.js)
- re-applied the fix to the $emit method - improved the the unit test - fixed spacing issue
1 parent 1843151 commit c0c5d8e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ng/rootScope.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -836,12 +836,14 @@ function $RootScopeProvider(){
836836
continue;
837837
}
838838
try {
839+
//allow all listeners attached to the current scope to run
839840
namedListeners[i].apply(null, listenerArgs);
840-
if (stopPropagation) return event;
841841
} catch (e) {
842842
$exceptionHandler(e);
843843
}
844844
}
845+
//if any listener on the current scope stops propagation, prevent bubbling
846+
if (stopPropagation) return event;
845847
//traverse upwards
846848
scope = scope.$parent;
847849
} while (scope);

test/ng/rootScopeSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,14 @@ describe('Scope', function() {
922922
expect(log).toEqual('2>1>0>');
923923
});
924924

925+
it('should allow all events on the same scope to run even if stopPropagation is called', function(){
926+
child.$on('myEvent', logger);
927+
grandChild.$on('myEvent', function(e) { e.stopPropagation(); });
928+
grandChild.$on('myEvent', logger);
929+
grandChild.$on('myEvent', logger);
930+
grandChild.$emit('myEvent');
931+
expect(log).toEqual('2>2>2>');
932+
});
925933

926934
it('should dispatch exceptions to the $exceptionHandler',
927935
inject(function($exceptionHandler) {

0 commit comments

Comments
 (0)