Overview
ThecreateLogoSoup() function creates the core processing engine that handles image loading, measurement, normalization, and caching. It returns a LogoSoupEngine instance with an imperative subscribe/getSnapshot interface.
This is the foundation of all framework adapters. For most use cases, you’ll use a framework-specific wrapper (React hook, Vue composable, etc.), but the engine can be used directly for custom integrations.
Signature
Return Type
Returns aLogoSoupEngine object with the following methods:
Triggers a processing run with the given options. Call this whenever your input logos or options change.Any in-flight processing from a previous call is automatically cancelled.
Subscribes to state changes. The listener is called whenever the engine’s state updates.Returns an unsubscribe function to remove the listener.
Returns the current immutable state snapshot.Important: Returns the same reference if nothing has changed, enabling efficient change detection.
Cleans up resources:
- Revokes all blob URLs created for cropped images
- Cancels any in-flight processing
- Clears the image cache
- Removes all listeners
State Shape
TheLogoSoupState object returned by getSnapshot() has the following structure:
Current processing status:
idle— Initial state before firstprocess()callloading— Loading or measuring imagesready— Processing complete, normalized logos availableerror— All logos failed to load
Array of successfully processed and normalized logos. Empty if not in
ready state or if all logos failed.See types for the complete structure.Error object if status is
error, otherwise null.Usage Example
Basic Usage
Rendering to DOM
Integration with Reactivity Systems
Thesubscribe/getSnapshot pattern is designed to integrate with any framework’s reactivity system:
Caching Behavior
The engine maintains an internal cache of loaded images and measurements:- Cache key: Image
srcURL - Cache invalidation: When
contrastThreshold,densityAware, orbackgroundColoroptions change, the entire cache is cleared - Cache pruning: When a logo is removed from the
logosarray, its cache entry (including blob URLs) is automatically cleaned up - Synchronous fast path: If all logos are cached and no new measurements are needed,
process()completes synchronously
Performance Considerations
- Synchronous when cached: Subsequent
process()calls with the same logos (and measurement options) complete instantly - Automatic cancellation: Calling
process()while another is in-flight cancels the previous one - Efficient change detection:
getSnapshot()returns the same object reference if nothing changed, enabling===checks - Memory management: Always call
destroy()to prevent blob URL leaks
Related
- ProcessOptions — Options passed to
process() - LogoSoupState — State object shape
- NormalizedLogo — Normalized logo structure
- getVisualCenterTransform — Compute alignment transforms