mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-13 01:13:08 +00:00
refactor(scope.$emit): rename event.cancel() to event.stopPropagation()
Breaks event.cancel() is event.stopPropagation()
This commit is contained in:
parent
acf095d178
commit
91db99208e
2 changed files with 6 additions and 18 deletions
|
|
@ -616,9 +616,8 @@ function $RootScopeProvider(){
|
||||||
* - `targetScope` - {Scope}: the scope on which the event was `$emit`-ed or `$broadcast`-ed.
|
* - `targetScope` - {Scope}: the scope on which the event was `$emit`-ed or `$broadcast`-ed.
|
||||||
* - `currentScope` - {Scope}: the current scope which is handling the event.
|
* - `currentScope` - {Scope}: the current scope which is handling the event.
|
||||||
* - `name` - {string}: Name of the event.
|
* - `name` - {string}: Name of the event.
|
||||||
* - `cancel` - {function=}: calling `cancel` function will cancel further event propagation
|
* - `stopPropagation` - {function=}: calling `stopPropagation` function will cancel further event propagation
|
||||||
* (available only for events that were `$emit`-ed).
|
* (available only for events that were `$emit`-ed).
|
||||||
* - `cancelled` - {boolean}: Whether the event was cancelled.
|
|
||||||
*/
|
*/
|
||||||
$on: function(name, listener) {
|
$on: function(name, listener) {
|
||||||
var namedListeners = this.$$listeners[name];
|
var namedListeners = this.$$listeners[name];
|
||||||
|
|
@ -659,11 +658,11 @@ function $RootScopeProvider(){
|
||||||
var empty = [],
|
var empty = [],
|
||||||
namedListeners,
|
namedListeners,
|
||||||
scope = this,
|
scope = this,
|
||||||
|
stopPropagation = false,
|
||||||
event = {
|
event = {
|
||||||
name: name,
|
name: name,
|
||||||
targetScope: scope,
|
targetScope: scope,
|
||||||
cancel: function() {event.cancelled = true;},
|
stopPropagation: function() {stopPropagation = true;}
|
||||||
cancelled: false
|
|
||||||
},
|
},
|
||||||
listenerArgs = concat([event], arguments, 1),
|
listenerArgs = concat([event], arguments, 1),
|
||||||
i, length;
|
i, length;
|
||||||
|
|
@ -674,7 +673,7 @@ function $RootScopeProvider(){
|
||||||
for (i=0, length=namedListeners.length; i<length; i++) {
|
for (i=0, length=namedListeners.length; i<length; i++) {
|
||||||
try {
|
try {
|
||||||
namedListeners[i].apply(null, listenerArgs);
|
namedListeners[i].apply(null, listenerArgs);
|
||||||
if (event.cancelled) return event;
|
if (stopPropagation) return event;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$exceptionHandler(e);
|
$exceptionHandler(e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -668,8 +668,8 @@ describe('Scope', function() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should allow cancelation of event propagation', function() {
|
it('should allow stopping event propagation', function() {
|
||||||
child.$on('myEvent', function(event) { event.cancel(); });
|
child.$on('myEvent', function(event) { event.stopPropagation(); });
|
||||||
grandChild.$emit('myEvent');
|
grandChild.$emit('myEvent');
|
||||||
expect(log).toEqual('2>1>');
|
expect(log).toEqual('2>1>');
|
||||||
});
|
});
|
||||||
|
|
@ -685,17 +685,6 @@ describe('Scope', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should return event object with cancelled property', function() {
|
|
||||||
child.$on('some', function(event) {
|
|
||||||
event.cancel();
|
|
||||||
});
|
|
||||||
|
|
||||||
var result = grandChild.$emit('some');
|
|
||||||
expect(result).toBeDefined();
|
|
||||||
expect(result.cancelled).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
describe('event object', function() {
|
describe('event object', function() {
|
||||||
it('should have methods/properties', function() {
|
it('should have methods/properties', function() {
|
||||||
var event;
|
var event;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue