Created
February 6, 2015 16:24
-
-
Save alloy-d/ee8e52f9a4dc47bc397f to your computer and use it in GitHub Desktop.
Minimal mixin for managing Bacon subscriptions alongside the React component lifecycle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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