Class ComponentObserver
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.polymertemplate.AbstractTemplate<M>
-
- com.vaadin.flow.component.polymertemplate.PolymerTemplate<com.vaadin.flow.templatemodel.TemplateModel>
-
- org.vaadin.miki.superfields.lazyload.ComponentObserver
-
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.template.internal.DeprecatedPolymerTemplate,com.vaadin.flow.internal.Template,Serializable,HasId,WithIdMixin<ComponentObserver>
- Direct Known Subclasses:
ObservedField.ObservedFieldElement
@JsModule("./component-observer.js") @Tag("component-observer") public class ComponentObserver extends com.vaadin.flow.component.polymertemplate.PolymerTemplate<com.vaadin.flow.templatemodel.TemplateModel> implements WithIdMixin<ComponentObserver>A component that wraps Intersection Observer on the client-side to notify server-side about visibility changes. Note: Intersection Observer API is experimental and not all browsers implement it.- Since:
- 2020-04-28
- Author:
- miki
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ComponentObserver(double... visibilityRanges)Creates the observer using entire document as viewport.ComponentObserver(com.vaadin.flow.component.Component viewportRoot, String rootMargin, double... visibilityRanges)Creates the observer using provided document as viewport root and provided root margins.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.vaadin.flow.shared.RegistrationaddComponentObservationListener(ComponentObservationListener listener)Adds a listener that will be informed about changes in observed components.protected voidfireComponentObservationEvent(ComponentObservationEvent event)Broadcasts the event usingComponent.getEventBus().double[]getVisibilityRanges()Returns an array with visibility ranges registered for this component.protected voidinitClient()booleanisObserving(com.vaadin.flow.component.Component component)Checks whether or not givenComponentis being observed by this object.voidobserve(com.vaadin.flow.component.Component... components)Starts observation of given components.protected voidobserve(String indexString, com.vaadin.flow.component.Component component)Observes the given component with given index.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent)protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent)voidunobserve(com.vaadin.flow.component.Component... components)Stops observation of given components.-
Methods inherited from class com.vaadin.flow.component.polymertemplate.AbstractTemplate
getModel, getModelType, getModelType, getStateNode, initModel, isSupportedClass
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, scrollIntoView, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.vaadin.miki.markers.WithIdMixin
withId
-
-
-
-
Constructor Detail
-
ComponentObserver
public ComponentObserver(double... visibilityRanges)
Creates the observer using entire document as viewport.- Parameters:
visibilityRanges- Ranges at which to trigger visibility change events. If not specified,[0.0, 1.0]will be used.
-
ComponentObserver
public ComponentObserver(com.vaadin.flow.component.Component viewportRoot, String rootMargin, double... visibilityRanges)Creates the observer using provided document as viewport root and provided root margins.- Parameters:
viewportRoot- Component to use as viewport root.rootMargin- Root margin (CSS-like expression).visibilityRanges- Ranges at which to trigger visibility change events. If not specified,[0.0, 1.0]will be used.
-
-
Method Detail
-
initClient
protected void initClient()
-
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
- Overrides:
onDetachin classcom.vaadin.flow.component.Component
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
- Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
fireComponentObservationEvent
protected void fireComponentObservationEvent(ComponentObservationEvent event)
Broadcasts the event usingComponent.getEventBus().- Parameters:
event- Event with relevant information about what happened.
-
observe
protected void observe(String indexString, com.vaadin.flow.component.Component component)
Observes the given component with given index. Will override the component currently associated with given index, if the was any.- Parameters:
indexString- Index string to register the component with.component- Component to observe.
-
observe
public void observe(com.vaadin.flow.component.Component... components)
Starts observation of given components. If a given component is already being observed, it will not be observed an additional time. Given component will stop being observed when it gets detached or whenunobserve(Component...)method is called.- Parameters:
components- Components to observe.
-
unobserve
public void unobserve(com.vaadin.flow.component.Component... components)
Stops observation of given components. If a given component has not been registered withobserve(Component...), nothing will happen.- Parameters:
components- Components to stop observing.
-
addComponentObservationListener
public com.vaadin.flow.shared.Registration addComponentObservationListener(ComponentObservationListener listener)
Adds a listener that will be informed about changes in observed components.- Parameters:
listener- Listener to add.- Returns:
- Registration that can be used to stop listening.
-
isObserving
public boolean isObserving(com.vaadin.flow.component.Component component)
Checks whether or not givenComponentis being observed by this object.- Parameters:
component- AComponent.- Returns:
truewhen thecomponenthas been added throughobserve(Component...)and not removed withunobserve(Component...).
-
getVisibilityRanges
public double[] getVisibilityRanges()
Returns an array with visibility ranges registered for this component. Modifying the resulting array has no effect on this object.- Returns:
- A non-empty array with visibility ranges.
-
-