Files
buuh/packages/bankai/lib/app.js
T

24 lines
975 B
JavaScript
Raw Normal View History

// The isomorphic entry contract (plan decision D5): the entry module's
// default export is either a choo app instance (typically
// `export default app.mount('body')` — mount() on the server records the
// selector and returns the app) or a factory returning one (preferred:
// fresh state per request). One module, three consumers: browser mount,
// server render, build metadata.
export function resolveApp (mod, entry) {
const value = mod && mod.default
if (!value) {
throw new Error(`bankai: ${entry} has no default export — export your choo app (or a function returning one)`)
}
// a factory is a plain function; an app instance has .mount
const app = typeof value === 'function' && !value.mount ? value() : value
if (typeof app.toStream !== 'function') {
throw new Error(`bankai: the default export of ${entry} is not a choo v8 app (missing toStream)`)
}
return app
}
export function selectorOf (app) {
return app.selector || 'body'
}