Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit ae22a6f

Browse files
committed
fix(scope): skip scopes whithot event on broadcast
1 parent a558a26 commit ae22a6f

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/core/scope.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,19 @@ class _Streams {
513513
scope = queue.removeFirst();
514514
scopeStreams = scope._streams;
515515
assert(scopeStreams._scope == scope);
516-
assert(scopeStreams._streams.containsKey(name));
517-
var stream = scopeStreams._streams[name];
518-
event._currentScope = scope;
519-
stream._fire(event);
516+
if(scopeStreams._streams.containsKey(name)) {
517+
var stream = scopeStreams._streams[name];
518+
event._currentScope = scope;
519+
stream._fire(event);
520+
}
520521
// Reverse traversal so that when the queue is read it is correct order.
521522
var childScope = scope._childTail;
522523
while(childScope != null) {
523524
scopeStreams = childScope._streams;
524-
if (scopeStreams != null) queue.addFirst(scopeStreams._scope);
525+
if (scopeStreams != null &&
526+
scopeStreams._typeCounts.containsKey(name)) {
527+
queue.addFirst(scopeStreams._scope);
528+
}
525529
childScope = childScope._prev;
526530
}
527531
}

test/core/scope_spec.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,19 @@ main() => describe('scope', () {
448448
expect(result.name).toBe('some');
449449
expect(result.targetScope).toBe(child1);
450450
}));
451+
452+
453+
it('should skip scopes which dont have given event',
454+
inject((RootScope rootScope, Logger log) {
455+
var child1 = rootScope.createChild('A');
456+
rootScope.createChild('A1');
457+
rootScope.createChild('A2');
458+
rootScope.createChild('A3');
459+
var child2 = rootScope.createChild('B');
460+
child2.on('event').listen((e) => log(e.data));
461+
rootScope.broadcast('event', 'OK');
462+
expect(log).toEqual(['OK']);
463+
}));
451464
});
452465

453466

0 commit comments

Comments
 (0)