@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
45 lines (44 loc) • 1.55 kB
JavaScript
import * as React from 'react';
import { createCoordinatedLazy } from "../CoordinatedLazy/createCoordinatedLazy.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
/**
* Factory-factory for chunked objects, mirroring `abstractCreateDemo`. Binds the
* chunk config and produces a component that renders the chunk with the build-
* time `precompute` (from `meta`) injected as its preloaded data - so a
* precomputed chunk renders directly, and a non-precomputed one falls back to
* the config's loaders.
*
* The `url` is the call-site identity (from `import.meta.url`) used by the
* build-time loader to inject `precompute`; it is not needed at runtime.
*/
export function abstractCreateStream(options, url, meta) {
const {
ClientProvider,
...config
} = options;
const Chunk = createCoordinatedLazy(config);
const preloaded = meta?.precompute;
const loaderOptions = meta?.loaderOptions;
function StreamObject(userProps) {
const chunk = /*#__PURE__*/_jsx(Chunk, {
preloaded: preloaded,
loaderOptions: loaderOptions,
userProps: userProps
});
if (ClientProvider) {
return /*#__PURE__*/_jsx(ClientProvider, {
children: chunk
});
}
return chunk;
}
StreamObject.displayName = 'StreamObject';
return StreamObject;
}
/**
* Bind chunk options once and get a `createStream(url, meta?)` entry
* point (mirrors `createDemoFactory` -> `createDemo`).
*/
export function createStreamFactory(options) {
return (url, meta) => abstractCreateStream(options, url, meta);
}