feat: unify card runtime and event-driven web ui
This commit is contained in:
parent
0edf8c3fef
commit
4dfb7ca3cc
105 changed files with 17382 additions and 8505 deletions
24
scripts/card_runtime_fixture_card.mjs
Normal file
24
scripts/card_runtime_fixture_card.mjs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
export function mount({ root, state, host }) {
|
||||
const render = (nextState) => {
|
||||
const title = typeof nextState.title === "string" ? nextState.title : "";
|
||||
root.innerHTML = `<div data-fixture-title="${title}">${title}</div>`;
|
||||
};
|
||||
|
||||
render(state);
|
||||
host.setLiveContent({ phase: "mount", title: state.title ?? "" });
|
||||
host.setRefreshHandler(() => {
|
||||
root.dataset.refreshed = "1";
|
||||
});
|
||||
|
||||
return {
|
||||
update({ state: nextState, host: nextHost }) {
|
||||
render(nextState);
|
||||
nextHost.setLiveContent({ phase: "update", title: nextState.title ?? "" });
|
||||
},
|
||||
destroy() {
|
||||
root.dataset.destroyed = "1";
|
||||
root.innerHTML = "";
|
||||
host.setRefreshHandler(null);
|
||||
},
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue