Skip to content

Commit c33fa93

Browse files
committed
Fix #572. Respect end in Bus.push
1 parent 04c754f commit c33fa93

5 files changed

Lines changed: 43 additions & 10 deletions

File tree

dist/Bacon.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function() {
2-
var Bacon, BufferingSource, Bus, CompositeUnsubscribe, ConsumingSource, Desc, Dispatcher, End, Error, Event, EventStream, Exception, Initial, Next, None, Observable, Property, PropertyDispatcher, Some, Source, UpdateBarrier, _, addPropertyInitValueToStream, assert, assertArray, assertEventStream, assertFunction, assertNoArguments, assertObservable, assertString, cloneArray, constantToFunction, containsDuplicateDeps, convertArgsToFunction, describe, endEvent, eventIdCounter, eventMethods, findDeps, findHandlerMethods, flatMap_, former, idCounter, initialEvent, isArray, isFieldKey, isObservable, latter, liftCallback, makeFunction, makeFunctionArgs, makeFunction_, makeObservable, makeSpawner, nextEvent, nop, partiallyApplied, recursionDepth, ref, registerObs, spys, toCombinator, toEvent, toFieldExtractor, toFieldKey, toOption, toSimpleExtractor, valueAndEnd, withDescription, withMethodCallSupport,
2+
var Bacon, BufferingSource, Bus, CompositeUnsubscribe, ConsumingSource, Desc, Dispatcher, End, Error, Event, EventStream, Exception, Initial, Next, None, Observable, Property, PropertyDispatcher, Some, Source, UpdateBarrier, _, addPropertyInitValueToStream, assert, assertArray, assertEventStream, assertFunction, assertNoArguments, assertObservable, assertObservableIsProperty, assertString, cloneArray, constantToFunction, containsDuplicateDeps, convertArgsToFunction, describe, endEvent, eventIdCounter, eventMethods, findDeps, findHandlerMethods, flatMap_, former, idCounter, initialEvent, isArray, isFieldKey, isObservable, latter, liftCallback, makeFunction, makeFunctionArgs, makeFunction_, makeObservable, makeSpawner, nextEvent, nop, partiallyApplied, recursionDepth, ref, registerObs, spys, toCombinator, toEvent, toFieldExtractor, toFieldKey, toOption, toSimpleExtractor, valueAndEnd, withDescription, withMethodCallSupport,
33
hasProp = {}.hasOwnProperty,
44
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
55
slice = [].slice,
@@ -11,7 +11,7 @@
1111
}
1212
};
1313

14-
Bacon.version = '0.7.53';
14+
Bacon.version = '<version>';
1515

1616
Exception = (typeof global !== "undefined" && global !== null ? global : this).Error;
1717

@@ -35,6 +35,12 @@
3535
}
3636
};
3737

38+
assertObservableIsProperty = function(x) {
39+
if (x instanceof Observable && !(x instanceof Property)) {
40+
throw new Exception("Observable is not a Property : " + x);
41+
}
42+
};
43+
3844
assertEventStream = function(event) {
3945
if (!(event instanceof EventStream)) {
4046
throw new Exception("not an EventStream : " + event);
@@ -2155,6 +2161,7 @@
21552161
Bacon.Observable.prototype.filter = function() {
21562162
var args, f;
21572163
f = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
2164+
assertObservableIsProperty(f);
21582165
return convertArgsToFunction(this, f, args, function(f) {
21592166
return withDescription(this, "filter", f, this.withHandler(function(event) {
21602167
if (event.filter(f)) {
@@ -2573,7 +2580,9 @@
25732580
};
25742581

25752582
Bus.prototype.push = function(value) {
2576-
return typeof this.sink === "function" ? this.sink(nextEvent(value)) : void 0;
2583+
if (!this.ended) {
2584+
return typeof this.sink === "function" ? this.sink(nextEvent(value)) : void 0;
2585+
}
25772586
};
25782587

25792588
Bus.prototype.error = function(error) {
@@ -3104,6 +3113,7 @@
31043113
Bacon.EventStream.prototype.skipWhile = function() {
31053114
var args, f, ok;
31063115
f = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
3116+
assertObservableIsProperty(f);
31073117
ok = false;
31083118
return convertArgsToFunction(this, f, args, function(f) {
31093119
return withDescription(this, "skipWhile", f, this.withHandler(function(event) {
@@ -3167,6 +3177,7 @@
31673177
Bacon.Observable.prototype.takeWhile = function() {
31683178
var args, f;
31693179
f = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
3180+
assertObservableIsProperty(f);
31703181
return convertArgsToFunction(this, f, args, function(f) {
31713182
return withDescription(this, "takeWhile", f, this.withHandler(function(event) {
31723183
if (event.filter(f)) {

dist/Bacon.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/Bacon.noAssert.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function () {
2-
var Bacon, BufferingSource, Bus, CompositeUnsubscribe, ConsumingSource, Desc, Dispatcher, End, Error, Event, EventStream, Exception, Initial, Next, None, Observable, Property, PropertyDispatcher, Some, Source, UpdateBarrier, _, addPropertyInitValueToStream, assert, assertArray, assertEventStream, assertFunction, assertNoArguments, assertObservable, assertString, cloneArray, constantToFunction, containsDuplicateDeps, convertArgsToFunction, describe, endEvent, eventIdCounter, eventMethods, findDeps, findHandlerMethods, flatMap_, former, idCounter, initialEvent, isArray, isFieldKey, isObservable, latter, liftCallback, makeFunction, makeFunctionArgs, makeFunction_, makeObservable, makeSpawner, nextEvent, nop, partiallyApplied, recursionDepth, ref, registerObs, spys, toCombinator, toEvent, toFieldExtractor, toFieldKey, toOption, toSimpleExtractor, valueAndEnd, withDescription, withMethodCallSupport, hasProp = {}.hasOwnProperty, extend = function (child, parent) {
2+
var Bacon, BufferingSource, Bus, CompositeUnsubscribe, ConsumingSource, Desc, Dispatcher, End, Error, Event, EventStream, Exception, Initial, Next, None, Observable, Property, PropertyDispatcher, Some, Source, UpdateBarrier, _, addPropertyInitValueToStream, assert, assertArray, assertEventStream, assertFunction, assertNoArguments, assertObservable, assertObservableIsProperty, assertString, cloneArray, constantToFunction, containsDuplicateDeps, convertArgsToFunction, describe, endEvent, eventIdCounter, eventMethods, findDeps, findHandlerMethods, flatMap_, former, idCounter, initialEvent, isArray, isFieldKey, isObservable, latter, liftCallback, makeFunction, makeFunctionArgs, makeFunction_, makeObservable, makeSpawner, nextEvent, nop, partiallyApplied, recursionDepth, ref, registerObs, spys, toCombinator, toEvent, toFieldExtractor, toFieldKey, toOption, toSimpleExtractor, valueAndEnd, withDescription, withMethodCallSupport, hasProp = {}.hasOwnProperty, extend = function (child, parent) {
33
for (var key in parent) {
44
if (hasProp.call(parent, key))
55
child[key] = parent[key];
@@ -21,7 +21,7 @@
2121
return 'Bacon';
2222
}
2323
};
24-
Bacon.version = '0.7.53';
24+
Bacon.version = '<version>';
2525
Exception = (typeof global !== 'undefined' && global !== null ? global : this).Error;
2626
nop = function () {
2727
};
@@ -2331,7 +2331,9 @@
23312331
return typeof this.sink === 'function' ? this.sink(endEvent()) : void 0;
23322332
};
23332333
Bus.prototype.push = function (value) {
2334-
return typeof this.sink === 'function' ? this.sink(nextEvent(value)) : void 0;
2334+
if (!this.ended) {
2335+
return typeof this.sink === 'function' ? this.sink(nextEvent(value)) : void 0;
2336+
}
23352337
};
23362338
Bus.prototype.error = function (error) {
23372339
return typeof this.sink === 'function' ? this.sink(new Error(error)) : void 0;
@@ -3050,4 +3052,4 @@
30503052
} else {
30513053
this.Bacon = Bacon;
30523054
}
3053-
}.call(this));
3055+
}.call(this));

spec/specs/bus.coffee

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ describe "Bacon.Bus", ->
9494
bus.onValue(->)
9595
expect(plugged).to.deep.equal(false)
9696

97+
it "respects end() even events comes from plugged stream", ->
98+
failed = false
99+
busA = new Bacon.Bus()
100+
busB = new Bacon.Bus()
101+
busB.onValue(-> failed = true;)
102+
busB.plug(busA)
103+
busB.end()
104+
busA.push('foo')
105+
expect(failed).to.equal(false)
106+
107+
it "does not plug after end(), second variant", ->
108+
failed = false
109+
busA = new Bacon.Bus()
110+
busB = new Bacon.Bus()
111+
busB.onValue(-> failed = true;)
112+
busB.plug(busA)
113+
busB.end()
114+
busA.push('foo')
115+
expect(failed).to.equal(false)
116+
97117
it "respects end() calls before subscribers", ->
98118
failed = false
99119
bus = new Bacon.Bus()

src/bus.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Bus extends EventStream
4848
@sink? endEvent()
4949

5050
push: (value) ->
51-
@sink? nextEvent(value)
51+
@sink? nextEvent(value) unless @ended
5252

5353
error: (error) ->
5454
@sink? new Error(error)

0 commit comments

Comments
 (0)