Class: SpiffCommerce2DPreviewService
Renders a single layout's design, read-only, into one or more registered views as real SVG/DOM content - crisp at any zoom for free, updated incrementally via React's own reconciliation rather than a full re-render per change.
Implements
Constructors
Constructor
new SpiffCommerce2DPreviewService(
options?):SpiffCommerce2DPreviewService
Parameters
options?
SpiffCommerce2DPreviewServiceOptions = {}
Returns
SpiffCommerce2DPreviewService
Methods
fireResizeEvent()
fireResizeEvent():
void
When called will trigger the internal engine to match the current view size. This ensures the image renders correctly in the view and also prevents performance problems.
Returns
void
Implementation of
TwoDPreviewService.fireResizeEvent
getInitializationComplete()
getInitializationComplete():
boolean
True when the preview has been initialized. This is when the initializationPromise resolves.
Returns
boolean
Implementation of
TwoDPreviewService.getInitializationComplete
getInitializationPromise()
getInitializationPromise():
Promise<void>
Returns a promise which resolves when the preview has been initialized.
Returns
Promise<void>
Implementation of
TwoDPreviewService.getInitializationPromise
getNumViewports()
getNumViewports():
number
Returns the number of active viewports registered with the preview. Useful for avoiding unnecessary rendering when there are no active viewers.
Returns
number
Implementation of
TwoDPreviewService.getNumViewports
registerView()
registerView(
view):void
Request that the preview renders to a given view. For a canvas-based engine (e.g. the 3D preview) this is an HTMLCanvasElement; other engines (e.g. the 2D preview) may render into any element, such as a container to mount live SVG/DOM content into.
Parameters
view
HTMLElement
The element we should render to.
Returns
void
Implementation of
TwoDPreviewService.registerView
setElement()
setElement(
element):void
Updates the content rendered into every registered view, and re-renders them immediately. Call whenever the underlying design/layout data changes.
Parameters
element
ReactNode
Returns
void
Implementation of
TwoDPreviewService.setElement
shutdown()
shutdown():
void
Shuts down the preview engine. Noop if the engine is not initialized.
Returns
void
Implementation of
TwoDPreviewService.shutdown
unregisterView()
unregisterView(
view):void
Tells the preview that we no longer want the given view to be rendered to.
Parameters
view
HTMLElement
The view to be excluded from rendering.
Returns
void
Implementation of
TwoDPreviewService.unregisterView