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

Function createStub

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

Source from the content-addressed store, hash-verified

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