styled-components
Version:
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
39 lines (34 loc) • 970 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* Creates a broadcast that can be listened to, i.e. simple event emitter
*
* @see https://github.com/ReactTraining/react-broadcast
*/
var createBroadcast = function createBroadcast(initialValue) {
var listeners = [];
var currentValue = initialValue;
return {
publish: function publish(value) {
currentValue = value;
listeners.forEach(function (listener) {
return listener(currentValue);
});
},
subscribe: function subscribe(listener) {
listeners.push(listener);
// Publish to this subscriber once immediately.
listener(currentValue);
// eslint-disable-next-line no-return-assign
return function () {
return listeners = listeners.filter(function (item) {
return item !== listener;
});
};
}
};
};
exports.default = createBroadcast;
module.exports = exports["default"];