Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

744 B
Raw Blame
import type { WidgetImplementation, WidgetImplementationResource, WidgetTypeId } from './widgetContracts';

import { createDeferredResource } from './deferredResource';

const validateImplementation = (widgetId: WidgetTypeId, value: WidgetImplementation): WidgetImplementation => {
  if (!value || typeof value !== 'object' || typeof value.view !== 'function') {
    throw new TypeError(`Widget ${widgetId} implementation must provide a view component.`);
  }

  return value;
};

export const createWidgetImplementationResource = (
  widgetId: WidgetTypeId,
  loader: () => Promise<WidgetImplementation>
): WidgetImplementationResource =>
  createDeferredResource(loader, (implementation) => validateImplementation(widgetId, implementation));