Skip to main content

Loader utilities / composition

Let a composite loader delegate without losing context.

parseFromContext() and its synchronous and batched variants provide a shared way for one loader to invoke another for embedded data or associated resources. Parent options, paths, and runtime context remain available to the sub-loader.

Delegated parsing

Keep nested formats inside the same loading contract.

A composite format can slice or locate embedded data, then call the appropriate sub-loader with the context that explains where that data came from and how related resources should resolve.

Locate

Extract embedded or associated content from the parent format.

Delegate

Call a sub-loader through the context-aware helper.

Preserve

Carry options, paths, and runtime hooks across the boundary.

Choose

Use async, sync, or batched variants for the nested data.

Detailed guide

parseFromContext reference

The detailed reference covers async, sync, and batched delegation, loader context, options, and composite-loader usage.

Use these helpers inside a composite loader to delegate parsing while retaining its loader context. They are exported from @loaders.gl/core/loader-utils.

Usage​

import {parseFromContext} from '@loaders.gl/core/loader-utils';
import {OBJLoader} from '@loaders.gl/scene/obj';

async function parseEmbeddedMesh(arrayBuffer, options, context) {
const meshBytes = arrayBuffer.slice(100, 200);
return await parseFromContext(meshBytes, OBJLoader, options, context);
}

Functions​

HelperResultRequirement
parseFromContext(data, loader, options, context)Promise of decoded dataParent parsing context.
parseSyncFromContext(data, loader, options, context)Decoded dataContext with synchronous parsing and a synchronous child parser.
parseInBatchesFromContext(data, loader, options, context)Promise of an async batch iterableContext with batched parsing.

Pass the context supplied to the parent parser. Published loader modules must not import core to make nested parsing calls. New implementations can also use the context.coreApi methods, passing the parent context explicitly.