MCPcopy Index your code
hub / github.com/pyscript/pyscript / onReady

Function onReady

core/src/core.js:197–249  ·  view source on GitHub ↗
(wrap, element)

Source from the content-addressed store, hash-verified

195 main: {
196 ...codeFor(main, TYPE),
197 async onReady(wrap, element) {
198 registerModule(wrap);
199
200 // allows plugins to do whatever they want with the element
201 // before regular stuff happens in here
202 for (const callback of main("onReady"))
203 await callback(wrap, element);
204
205 // now that all possible plugins are configured,
206 // bail out if polyscript encountered an error
207 if (errors.has(element)) {
208 let { message } = errors.get(element);
209 errors.delete(element);
210 const clone = message === INVALID_CONTENT;
211 message = `(${ErrorCode.CONFLICTING_CODE}) ${message} for `;
212 message += element.cloneNode(clone).outerHTML;
213 wrap.io.stderr(message);
214 return;
215 }
216
217 if (isScript(element)) {
218 const isAsync = !isSync(element);
219 const target = element.getAttribute("target");
220 const show = target
221 ? queryTarget(element, target)
222 : document.createElement("script-py");
223
224 if (!target) {
225 const { head, body } = document;
226 if (head.contains(element)) body.append(show);
227 else element.after(show);
228 }
229 if (!show.id) show.id = getID();
230
231 // allows the code to retrieve the target element via
232 // document.currentScript.target if needed
233 defineProperty(element, "target", { value: show });
234
235 // notify before the code runs
236 dispatch(element, TYPE, "ready");
237 dispatchDone(
238 element,
239 isAsync,
240 wrap[`run${isAsync ? "Async" : ""}`](
241 await fetchSource(element, wrap.io, true),
242 ),
243 );
244 } else {
245 // resolve PyScriptElement to allow connectedCallback
246 element._wrap.resolve(wrap);
247 }
248 console.debug("[pyscript/main] PyScript Ready");
249 },
250 onWorker(_, xworker) {
251 assign(xworker.sync, sync);
252 for (const callback of main("onWorker"))

Callers

nothing calls this directly

Calls 13

mainFunction · 0.90
createFunctionFunction · 0.90
registerModuleFunction · 0.85
callbackFunction · 0.85
isScriptFunction · 0.85
dispatchDoneFunction · 0.85
fetchSourceFunction · 0.85
hasMethod · 0.80
debugMethod · 0.80
getIDFunction · 0.70
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected