{"version":3,"file":"brcast.umd.min.js","sources":["../index.js"],"sourcesContent":["export default function createBroadcast (initialState) {\n let listeners = {}\n let id = 0\n let _state = initialState\n\n const getState = () => _state\n\n const setState = state => {\n _state = state\n const keys = Object.keys(listeners)\n for (let i = 0; i < keys.length; i += 1) {\n // if a listener gets unsubscribed during setState we just skip it\n if (typeof listeners[keys[i]] !== 'undefined') {\n listeners[keys[i]](state)\n }\n }\n }\n\n const subscribe = listener => {\n if (typeof listener !== 'function') { throw new Error('listener must be a function.') }\n const currentId = id\n let isSubscribed = true\n listeners[currentId] = listener\n id += 1\n return function unsubscribe () {\n // in case unsubscribe gets called multiple times we simply return\n if (!isSubscribed) return\n isSubscribed = false\n delete listeners[currentId]\n }\n }\n\n return { getState, setState, subscribe }\n}\n"],"names":["createBroadcast","initialState","let","listeners","id","_state","getState","setState","state","keys","Object","i","length","subscribe","listener","Error","const","currentId","isSubscribed"],"mappings":"qKAAe,QAASA,GAAiBC,GACvCC,GAAIC,MACAC,EAAK,EACLC,EAASJ,CA6Bb,QAASK,SA3BQ,iBAAMD,IA2BJE,SAzBF,SAAAC,GACfH,EAASG,CAET,KAAKN,GADCO,GAAOC,OAAOD,KAAKN,GAChBQ,EAAI,EAAGA,EAAIF,EAAKG,OAAQD,GAAK,MAEF,KAAvBR,EAAUM,EAAKE,KACxBR,EAAUM,EAAKE,IAAIH,IAmBIK,UAdX,SAAAC,GAChB,GAAwB,kBAAbA,GAA2B,KAAM,IAAIC,OAAM,+BACtDC,IAAMC,GAAYb,EACdc,GAAe,CAGnB,OAFAf,GAAUc,GAAaH,EACvBV,GAAM,EACC,WAEAc,IACLA,GAAe,QACRf,GAAUc"}