import { Burpanet } from "../index.js"; import "./browser-shim.js" export class BurpaConfig extends HTMLElement { connectedCallback() { for (let att of ["local"]) { let a = this.getAttribute(att); if (a) { this.attributeChangedCallback(att, "", a); } } } attributeChangedCallback(id: string, oldVal: string, newVal: string) { switch (id) { case "local": Burpanet.whenInit.then(() => { let p = Burpanet.spawnHost(newVal, {}); p.then((name: string | null) => { if (name) { // console.warn(`Have spawned local = ${name}`); // if (Burpanet.state.whole.persistent.localHost) { // Burpanet.state.whole.persistent.localHost = name; if (Burpanet.state.whole.persistent.localHost) { Burpanet.state.whole.persistent.aliases[name] = Burpanet.state.whole.persistent.localHost!; } else { Burpanet.state.whole.persistent.localHost = name; } // throw new Error(`todo! replace local host ${Burpanet.state.whole.persistent.localHost}`); // } else { // throw new Error(`todo! set local host ${Burpanet.state.whole.persistent.localHost}`); // console.log("Have spawned", Burpanet.state.whole.persistent.localHost); // } } else { console.warn(`Failed to spawn ${newVal} spawn returned ${name}`); } }) }); break; } } } customElements.define("burpa-config", BurpaConfig);