| 11 | import platform from './main/platform.js'; |
| 12 | |
| 13 | export const dom = (ctx) => { |
| 14 | const state = makeState(); |
| 15 | let errorMsg = null; |
| 16 | // Surfaces async errors (listener throws, observer callbacks, swallowed promise rejections) to Python. Falls back to console.error if no consumer bound via bind_global_error. |
| 17 | const emitError = (where, e) => { |
| 18 | if (errorMsg) ctx.pushEvent(JSON.stringify({ |
| 19 | msg: errorMsg, |
| 20 | where, |
| 21 | error: (e && e.message) ? e.message : String(e), |
| 22 | stack: (e && e.stack) ? e.stack : undefined, |
| 23 | })); |
| 24 | else console.error(`[dom:${where}]`, e); |
| 25 | }; |
| 26 | const ctxPlus = { ...ctx, emitError }; |
| 27 | return Object.assign( |
| 28 | {}, |
| 29 | tree(state), |
| 30 | style(state), |
| 31 | events(state, ctxPlus), |
| 32 | forms(state, ctxPlus), |
| 33 | observers(state, ctxPlus), |
| 34 | animations(state, ctxPlus), |
| 35 | media(state, ctxPlus), |
| 36 | platform(state, ctxPlus), |
| 37 | { bind_global_error: (msg) => { errorMsg = msg; } }, |
| 38 | ); |
| 39 | }; |
| 40 | |
| 41 | export default dom; |