MCPcopy Index your code
hub / github.com/bigskysoftware/_hyperscript / createStub

Function createStub

src/ext/eventsource.js:183–241  ·  view source on GitHub ↗
(withCredentials, method, headers)

Source from the content-addressed store, hash-verified

181// ========================================
182
183function createStub(withCredentials, method, headers) {
184 var stub = {
185 listeners: [],
186 retryCount: 0,
187 closed: false,
188 abortController: null,
189 reader: null,
190 lastEventId: null,
191 reconnectTimeout: null,
192 url: null,
193 withCredentials: withCredentials,
194 method: method,
195 headers: headers,
196
197 open: function (url) {
198 if (url == undefined) {
199 if (stub.url != null) {
200 url = stub.url;
201 } else {
202 throw new Error("no url defined for EventSource.");
203 }
204 }
205
206 // If already connected to same URL, skip
207 if (stub.url === url && stub.abortController && !stub.abortController.signal.aborted) {
208 return;
209 }
210
211 // Close existing connection if URL changed or reconnecting
212 if (stub.abortController) {
213 stub.abortController.abort();
214 }
215
216 stub.closed = false;
217 stub.url = url;
218 startConnection(stub);
219 },
220
221 close: function () {
222 stub.closed = true;
223 if (stub.reconnectTimeout) {
224 clearTimeout(stub.reconnectTimeout);
225 stub.reconnectTimeout = null;
226 }
227 if (stub.abortController) {
228 stub.abortController.abort();
229 stub.abortController = null;
230 }
231 stub.retryCount = 0;
232 dispatch(stub, 'close', { type: 'close' });
233 },
234
235 addEventListener: function (type, handler, options) {
236 stub.listeners.push({ type: type, handler: handler, options: options });
237 },
238 };
239
240 return stub;

Callers 1

parseMethod · 0.70

Calls 3

startConnectionFunction · 0.70
dispatchFunction · 0.70
clearTimeoutFunction · 0.50

Tested by

no test coverage detected