Skip to content

Commit 1584d55

Browse files
committed
Redefine component.plug to use component.subscribeTo
1 parent 68aa691 commit 1584d55

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/react-bacon.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,11 @@ module.exports.BaconMixin = ((function(){
7171
var bacon = this._bacon = this._bacon || {};
7272
var unsubscribers = bacon.unsubscribers = bacon.unsubscribers || [];
7373
unsubscribers.push(unsub);
74+
return unsub;
7475
},
7576
plug: function(stream, stateKey) {
7677
var unsubscribe;
7778
var component = this;
78-
var bacon = this._bacon = this._bacon || {};
79-
var unsubscribers = bacon.unsubscribers = bacon.unsubscribers || [];
80-
8179
if (stateKey == null) {
8280
unsubscribe = stream.onValue(function(partialState) {
8381
component.setState(partialState);
@@ -89,8 +87,7 @@ module.exports.BaconMixin = ((function(){
8987
component.setState(partialState);
9088
});
9189
}
92-
unsubscribers.push(unsubscribe);
93-
return unsubscribe;
90+
return this.subscribeTo(unsubscribe);
9491
},
9592
componentDidUpdate: function() {
9693
var bacon = this._bacon;
@@ -118,7 +115,7 @@ module.exports.BaconMixin = ((function(){
118115

119116
var unsubscribers = bacon.unsubscribers;
120117
if (unsubscribers) {
121-
unsubscribers.forEach(function(f) {f()});
118+
unsubscribers.forEach(function(f) {f();});
122119
}
123120
}
124121
}

0 commit comments

Comments
 (0)