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

Function createStub

www/js/_hyperscript-max.js:11718–11767  ·  view source on GitHub ↗
(withCredentials, method, headers)

Source from the content-addressed store, hash-verified

11716 }
11717 };
11718 function createStub(withCredentials, method, headers) {
11719 var stub = {
11720 listeners: [],
11721 retryCount: 0,
11722 closed: false,
11723 abortController: null,
11724 reader: null,
11725 lastEventId: null,
11726 reconnectTimeout: null,
11727 url: null,
11728 withCredentials,
11729 method,
11730 headers,
11731 open: function(url) {
11732 if (url == void 0) {
11733 if (stub.url != null) {
11734 url = stub.url;
11735 } else {
11736 throw new Error("no url defined for EventSource.");
11737 }
11738 }
11739 if (stub.url === url && stub.abortController && !stub.abortController.signal.aborted) {
11740 return;
11741 }
11742 if (stub.abortController) {
11743 stub.abortController.abort();
11744 }
11745 stub.closed = false;
11746 stub.url = url;
11747 startConnection(stub);
11748 },
11749 close: function() {
11750 stub.closed = true;
11751 if (stub.reconnectTimeout) {
11752 clearTimeout(stub.reconnectTimeout);
11753 stub.reconnectTimeout = null;
11754 }
11755 if (stub.abortController) {
11756 stub.abortController.abort();
11757 stub.abortController = null;
11758 }
11759 stub.retryCount = 0;
11760 dispatch(stub, "close", { type: "close" });
11761 },
11762 addEventListener: function(type, handler, options) {
11763 stub.listeners.push({ type, handler, options });
11764 }
11765 };
11766 return stub;
11767 }
11768 function startConnection(stub) {
11769 var ac = new AbortController();
11770 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