Skip to content

Instantly share code, notes, and snippets.

@alloy-d
Created February 6, 2015 16:24
Show Gist options
  • Save alloy-d/ee8e52f9a4dc47bc397f to your computer and use it in GitHub Desktop.
Save alloy-d/ee8e52f9a4dc47bc397f to your computer and use it in GitHub Desktop.
Minimal mixin for managing Bacon subscriptions alongside the React component lifecycle.
define(function () {
"use strict";
var Subscriber = {
componentDidMount: function () {
this._unsubscribers = [];
},
componentWillUnmount: function () {
var i, len = this._unsubscribers.length;
for (i = 0; i < len; i += 1) {
this._unsubscribers[i]();
}
},
subscribe: function (unsubscribeFunc) {
this._unsubscribers.push(unsubscribeFunc);
}
};
return Subscriber;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment