the given code should log the following
Creating: child 0
Creating: child 1
Bye from: child 0
Bye from: child 1
but 'Bye from: child 1' is never logged. From looking at the signal implementation the _observers array is a reference that disconnectAll/disconnect mutates when a signal is disconnected, changing the indexes.
Changing the signal implementation to copy the array to a local variable rather than a reference before signaling fixes the problem. (this was a fun one to track down!)
var idgen = imap(partial(operator.add, 'child '), count())
var parent = {foo: function(){log('Should Not be called')}}
function Child()
{
this.id = idgen.next()
log("Creating:", this.id)
}
Child.prototype = {
bye: function()
{
log('Bye from:', this.id)
disconnectAll(this)
}
}
var c1 = new Child()
var c2 = new Child()
connect(c1, 'anysig', parent, 'foo')
connect(c2, 'anysig', parent, 'foo')
connect(parent, 'hello', c1, 'bye')
connect(parent, 'hello', c2, 'bye')
signal(parent, 'hello')