MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / createStub

Function createStub

www/js/ext/eventsource.esm.js:196–245  ·  view source on GitHub ↗
(withCredentials, method, headers)

Source from the content-addressed store, hash-verified

194 }
195};
196function createStub(withCredentials, method, headers) {
197 var stub = {
198 listeners: [],
199 retryCount: 0,
200 closed: false,
201 abortController: null,
202 reader: null,
203 lastEventId: null,
204 reconnectTimeout: null,
205 url: null,
206 withCredentials,
207 method,
208 headers,
209 open: function(url) {
210 if (url == void 0) {
211 if (stub.url != null) {
212 url = stub.url;
213 } else {
214 throw new Error("no url defined for EventSource.");
215 }
216 }
217 if (stub.url === url && stub.abortController && !stub.abortController.signal.aborted) {
218 return;
219 }
220 if (stub.abortController) {
221 stub.abortController.abort();
222 }
223 stub.closed = false;
224 stub.url = url;
225 startConnection(stub);
226 },
227 close: function() {
228 stub.closed = true;
229 if (stub.reconnectTimeout) {
230 clearTimeout(stub.reconnectTimeout);
231 stub.reconnectTimeout = null;
232 }
233 if (stub.abortController) {
234 stub.abortController.abort();
235 stub.abortController = null;
236 }
237 stub.retryCount = 0;
238 dispatch(stub, "close", { type: "close" });
239 },
240 addEventListener: function(type, handler, options) {
241 stub.listeners.push({ type, handler, options });
242 }
243 };
244 return stub;
245}
246function startConnection(stub) {
247 var ac = new AbortController();
248 stub.abortController = ac;

Callers 1

parseMethod · 0.70

Calls 3

startConnectionFunction · 0.70
dispatchFunction · 0.70
clearTimeoutFunction · 0.50

Tested by

no test coverage detected