@adobe/data - v0.10.30
    Preparing search index...
    • Creates a lazy-loading wrapper factory for an AsyncDataService. By default the real service is only loaded when the first property is accessed. All calls are queued and executed in order once the service loads.

      Type Parameters

      • LoadFn extends (...args: any[]) => Promise<Service>
      • const S extends LazyServiceSchema

      Parameters

      • params: { load: LoadFn; preload?: boolean; schema: S } & (
            EquivalentTypes<ToType<S, 5>, Omit<InferService<LoadFn>, keyof Service>> extends true
                ? unknown
                : {
                    schema: {
                        __createLazyError: "createLazy: schema must completely and correctly describe the loaded service";
                    };
                }
        )

        load returns the real service (may accept args); schema is the service's sideloaded object schema (e.g. typeof MyService.schema), which drives how each member is wrapped; preload (default false) warms the service at browser idle instead of waiting for the first property access.

      Returns InferArgs<LoadFn> extends void
          ? () => InferService<LoadFn>
          : (args: InferArgs<LoadFn>) => InferService<LoadFn>

      A factory function that creates lazy service instances

      TypeScript enforces that schema describes every member of the loaded service with the correct wrapper kind; otherwise the schema argument fails to type-check with a __createLazyError marker. This is the ONLY requirement — createLazy does NOT require the service to be a valid AsyncDataService, so a service that returns non-Data (e.g. Promise<Response>) can still be lazily loaded. Enforce AsyncDataService.IsValid separately at the service definition site if you want it. Note: member value/parameter schemas authored as {} resolve to any, so presence and wrapper kind are checked but inner payload types are only verified where a precise value/parameter schema is supplied.

      // Service with no args
      const createLazySimple = createLazy({
      load: () => import('./simple').then(m => m.create()),
      schema: SimpleService.schema,
      });
      const service = createLazySimple();

      // Service with args, warmed at browser idle
      const createLazyConfig = createLazy({
      load: (config: Config) => import('./service').then(m => m.create(config)),
      schema: ConfigService.schema,
      preload: true,
      });
      const service = createLazyConfig({ apiUrl: '...' });