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.

920 B
Raw Blame
import type {
  CanvasApplicationOperationStores,
  CanvasApplicationScalarStore,
} from '@workbench/canvas-operations/contracts';

export type CanvasOperationScalarStore<T> = CanvasApplicationScalarStore<T>;
export type CanvasOperationStores = CanvasApplicationOperationStores;

const createScalarStore = <T>(initial: T): CanvasOperationScalarStore<T> => {
  let value = initial;
  const listeners = new Set<() => void>();
  return {
    get: () => value,
    set: (next) => {
      if (Object.is(value, next)) {
        return;
      }
      value = next;
      for (const listener of listeners) {
        listener();
      }
    },
    subscribe: (listener) => {
      listeners.add(listener);
      return () => listeners.delete(listener);
    },
  };
};

export const createCanvasOperationStores = (): CanvasOperationStores => ({
  filterSession: createScalarStore(null),
  samSession: createScalarStore(null),
});