MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / createBroadcast

Function createBroadcast

code/styling/public/app.js:21205–21238  ·  view source on GitHub ↗
(initialState)

Source from the content-addressed store, hash-verified

21203 */
21204
21205var createBroadcast = function createBroadcast(initialState) {
21206 var listeners = {};
21207 var id = 0;
21208 var state = initialState;
21209
21210 function publish(nextState) {
21211 state = nextState;
21212
21213 // eslint-disable-next-line guard-for-in, no-restricted-syntax
21214 for (var key in listeners) {
21215 var listener = listeners[key];
21216 if (listener === undefined) {
21217 // eslint-disable-next-line no-continue
21218 continue;
21219 }
21220
21221 listener(state);
21222 }
21223 }
21224
21225 function subscribe(listener) {
21226 var currentId = id;
21227 listeners[currentId] = listener;
21228 id += 1;
21229 listener(state);
21230 return currentId;
21231 }
21232
21233 function unsubscribe(unsubID) {
21234 listeners[unsubID] = undefined;
21235 }
21236
21237 return { publish: publish, subscribe: subscribe, unsubscribe: unsubscribe };
21238};
21239
21240var _ThemeProvider$childC;
21241var _ThemeProvider$contex;

Callers 1

app.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected