stackchain-dashboard/frontend/conversation-action-hydrator.js
timmy 8b4bd480cc
All checks were successful
CI / lint (pull_request) Successful in 2m43s
CI / build-release (pull_request) Successful in 6s
CI / browser-journey (pull_request) Successful in 1m56s
CI / release-candidate (pull_request) Has been skipped
feat: correct recent Today updates in place (Closes #1062)
2026-08-18 04:46:53 +00:00

45 lines
1.0 KiB
JavaScript

function createConversationActionHydrator({ load, activate }) {
let actions = null;
let pending = null;
const wired = new WeakSet();
async function ensure() {
if (actions) return actions;
if (!pending) pending = load().then(() => actions = activate()).catch(error => {
pending = null;
throw error;
});
return pending;
}
function show({ root, state, paint, wire, retry }) {
if (actions) {
retry.hidden = true;
if (!wired.has(root)) {
wire(actions);
wired.add(root);
}
paint(state, actions);
return Promise.resolve(true);
}
paint(state, null);
retry.hidden = true;
return ensure().then(controller => {
if (!wired.has(root)) {
wire(controller);
wired.add(root);
}
paint(state, controller);
return true;
}).catch(() => {
retry.hidden = false;
return false;
});
}
return {show,get:ensure};
}
if (typeof module !== 'undefined' && module.exports) module.exports = createConversationActionHydrator;