text: var e=e=>{e.addFeature("eventsource",function(e,n,t){if(t.matchToken("eventsource")){var r,o=!1,u=e.requireElement("dotOrColonPath",t).evaluate().split("."),i=u.pop();t.matchToken("from")&&(r=e.requireElement("stringLike",t)),t.matchToken("with")&&t.matchToken("credentials")&&(o=!0);for(var a={eventSource:null,listeners:[],retryCount:0,open:function(e){if(null==e){if(null==a.eventSource||null==a.eventSource.url)throw"no url defined for EventSource.";e=a.eventSource.url}if(null!=a.eventSource)if(e!=a.eventSource.url)a.eventSource.close();else if(a.eventSource.readyState!=EventSource.CLOSED)return;a.eventSource=new EventSource(e,{withCredentials:o}),a.eventSource.addEventListener("open",function(e){a.retryCount=0}),a.eventSource.addEventListener("error",function(e){if(a.eventSource.readyState==EventSource.CLOSED){a.retryCount=Math.min(7,a.retryCount+1);var n=Math.random()*(2^a.retryCount)*500;window.setTimeout(a.open,n)}});for(var n=0;n<a.listeners.length;n++){var t=a.listeners[n];a.eventSource.addEventListener(t.type,t.handler,t.options)}},close:function(){null!=a.eventSource&&a.eventSource.close(),a.retryCount=0},addEventListener:function(e,n,t){a.listeners.push({type:e,handler:n,options:t}),null!=a.eventSource&&a.eventSource.addEventListener(e,n,t)}},c={name:i,object:a,install:function(e){n.assignToNamespace(e,u,i,a)}};t.matchToken("on");){var l=e.requireElement("stringLike",t,"Expected event name").evaluate(),v="";t.matchToken("as")&&(v=e.requireElement("stringLike",t,"Expected encoding type").evaluate());var s=e.requireElement("commandList",t);f(s),t.requireToken("end"),a.listeners.push({type:l,handler:d(v,s)})}return t.requireToken("end"),null!=r&&a.open(r.evaluate()),c;function d(e,t){return function(r){var o=function(e,n){return"json"==n?JSON.parse(e):e}(r.data,e),u=n.makeContext(a,c,a);u.event=r,u.result=o,t.execute(u)}}function f(e){if(e.next)return f(e.next);e.next={type:"implicitReturn",op:function(e){return n.HALT},execute:function(e){}}}}})};export{e as default};
  //# sourceMappingURL=eventsource.modern.js.map
  