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

Commit 91db992

Browse files
committed
refactor(scope.$emit): rename event.cancel() to event.stopPropagation()
Breaks event.cancel() is event.stopPropagation()
1 parent acf095d commit 91db992

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

src/ng/rootScope.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,8 @@ function $RootScopeProvider(){
616616
* - `targetScope` - {Scope}: the scope on which the event was `$emit`-ed or `$broadcast`-ed.
617617
* - `currentScope` - {Scope}: the current scope which is handling the event.
618618
* - `name` - {string}: Name of the event.
619-
* - `cancel` - {function=}: calling `cancel` function will cancel further event propagation
619+
* - `stopPropagation` - {function=}: calling `stopPropagation` function will cancel further event propagation
620620
* (available only for events that were `$emit`-ed).
621-
* - `cancelled` - {boolean}: Whether the event was cancelled.
622621
*/
623622
$on: function(name, listener) {
624623
var namedListeners = this.$$listeners[name];
@@ -659,11 +658,11 @@ function $RootScopeProvider(){
659658
var empty = [],
660659
namedListeners,
661660
scope = this,
661+
stopPropagation = false,
662662
event = {
663663
name: name,
664664
targetScope: scope,
665-
cancel: function() {event.cancelled = true;},
666-
cancelled: false
665+
stopPropagation: function() {stopPropagation = true;}
667666
},
668667
listenerArgs = concat([event], arguments, 1),
669668
i, length;
@@ -674,7 +673,7 @@ function $RootScopeProvider(){
674673
for (i=0, length=namedListeners.length; i<length; i++) {
675674
try {
676675
namedListeners[i].apply(null, listenerArgs);
677-
if (event.cancelled) return event;
676+
if (stopPropagation) return event;
678677
} catch (e) {
679678
$exceptionHandler(e);
680679
}

test/ng/rootScopeSpec.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,8 @@ describe('Scope', function() {
668668
}));
669669

670670

671-
it('should allow cancelation of event propagation', function() {
672-
child.$on('myEvent', function(event) { event.cancel(); });
671+
it('should allow stopping event propagation', function() {
672+
child.$on('myEvent', function(event) { event.stopPropagation(); });
673673
grandChild.$emit('myEvent');
674674
expect(log).toEqual('2>1>');
675675
});
@@ -685,17 +685,6 @@ describe('Scope', function() {
685685
});
686686

687687

688-
it('should return event object with cancelled property', function() {
689-
child.$on('some', function(event) {
690-
event.cancel();
691-
});
692-
693-
var result = grandChild.$emit('some');
694-
expect(result).toBeDefined();
695-
expect(result.cancelled).toBe(true);
696-
});
697-
698-
699688
describe('event object', function() {
700689
it('should have methods/properties', function() {
701690
var event;

0 commit comments

Comments
 (0)