( mountID, viewID, reactpyServerHost, useActivateButton, )
| 3 | let didMountDebug = false; |
| 4 | |
| 5 | export function mountWidgetExample( |
| 6 | mountID, |
| 7 | viewID, |
| 8 | reactpyServerHost, |
| 9 | useActivateButton, |
| 10 | ) { |
| 11 | let reactpyHost, reactpyPort; |
| 12 | if (reactpyServerHost) { |
| 13 | [reactpyHost, reactpyPort] = reactpyServerHost.split(":", 2); |
| 14 | } else { |
| 15 | reactpyHost = window.location.hostname; |
| 16 | reactpyPort = window.location.port; |
| 17 | } |
| 18 | |
| 19 | const client = new SimpleReactPyClient({ |
| 20 | serverLocation: { |
| 21 | url: `${window.location.protocol}//${reactpyHost}:${reactpyPort}`, |
| 22 | route: "/", |
| 23 | query: `?view_id=${viewID}`, |
| 24 | }, |
| 25 | }); |
| 26 | |
| 27 | const mountEl = document.getElementById(mountID); |
| 28 | let isMounted = false; |
| 29 | triggerIfInViewport(mountEl, () => { |
| 30 | if (!isMounted) { |
| 31 | activateView(mountEl, client, useActivateButton); |
| 32 | isMounted = true; |
| 33 | } |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | function activateView(mountEl, client, useActivateButton) { |
| 38 | if (!useActivateButton) { |
nothing calls this directly
no test coverage detected