public final class DataDiffSection<T> extends Section
DiffSectionSpec that creates a changeSet diffing a generic List of data.
This Section emits the following events:
RenderEvent whenever it needs a Component to render a model T from the List<? extends T> data. Providing a handler for this OnEvent is mandatory.
OnCheckIsSameItemEvent whenever during a diffing it wants to check whether two items
represent the same piece of data.
OnCheckIsSameContentEvent whenever during a diffing it wants to check whether two
items that represent the same piece of data have exactly the same content.
Diffing happens when the new List<? extends T> data is provided. Changes in State alone will not trigger diffing.
OnCheckIsSameItemEvent returns false RenderEvent is triggered. Otherwise
OnCheckIsSameContentEvent is called.
OnCheckIsSameContentEvent returns false RenderEvent is triggered.
OnCheckIsSameItemEvent is not implemented, new List<? extends T> data is
considered to be completely different and relayout will happen on every data update.
Example usage:
'@'GroupSectionSpec
public class MyGroupSectionSpec {
'@'OnCreateChildren
static Children onCreateChildren(
SectionContext c,
'@'Prop List extends Model> modelList) {
return Children.create()
.child(
DataDiffSection.create(c)
.data(modelList)
.renderEventHandler(MyGroupSection.onRender(c))
.onCheckIsSameItemEventHandler(MyGroupSection.onCheckIsSameItem(c))
.onCheckIsSameContentEventHandler(...))
.build();
}
'@'OnEvent(OnCheckIsSameItemEvent.class)
static boolean onCheckIsSameItem(SectionContext c, @FromEvent Model previousItem, @FromEvent Model nextItem) {
return previousItem.getId() == nextItem.getId();
}
'@'OnEvent(RenderEvent.class)
static RenderInfo onRender(SectionContext c, @FromEvent Model model) {
return ComponentRenderInfo.create()
.component(MyComponent.create(c).model(model).build())
.build();
}
}
com.facebook.litho.sections.common.DataDiffSectionSpec| Modifier and Type | Class and Description |
|---|---|
static class |
DataDiffSection.Builder<T> |
| Modifier and Type | Method and Description |
|---|---|
static <T> DataDiffSection.Builder<T> |
create(SectionContext context) |
protected void |
generateChangeSet(SectionContext c,
ChangeSet changeSet,
SectionContext _prevScopedContext,
Section _prevAbstractImpl,
SectionContext _nextScopedContext,
Section _nextAbstractImpl)
This method will delegate to the
DiffSectionSpec method annotated with OnDiff |
static <T> EventHandler<OnCheckIsSameContentEvent<T>> |
getOnCheckIsSameContentEventHandler(SectionContext context) |
static <T> EventHandler<OnCheckIsSameItemEvent<T>> |
getOnCheckIsSameItemEventHandler(SectionContext context) |
static <T> EventHandler<RenderEvent<T>> |
getRenderEventHandler(SectionContext context) |
boolean |
isDiffSectionSpec() |
boolean |
isEquivalentProps(Section other,
boolean shouldCompareCommonProps) |
protected java.lang.String |
verifyChangeSet(SectionContext context) |
createStateContainer, generateUniqueGlobalKeyForChild, getChildren, getEventDispatcher, getGlobalKey, getLogTag, getParent, getScopedContext, getSimpleName, getStateContainer, getStateContainer, isEquivalentTo, makeShallowCopy, makeShallowCopy, recordEventTrigger, setChildren, setCount, setGlobalKey, setKey, setScopedContext, setStateContaineracceptTriggerEvent, acceptTriggerEventImpl, bindService, createChildren, createInitialState, createService, dataBound, dataRendered, dispatchLoadingEvent, dispatchOnEvent, dispatchOnEventImpl, getEventTrigger, getEventTrigger, getLoadingEventHandler, getService, getTreePropsForChildren, isSectionIndexValid, newEventHandler, newEventTrigger, newEventTrigger, populateTreeProps, refresh, requestFocus, requestFocus, requestFocus, requestFocusWithOffset, requestFocusWithOffset, requestFocusWithOffset, requestSmoothFocus, requestSmoothFocus, requestSmoothFocus, shouldUpdate, transferService, transferState, unbindService, viewportChangedpublic boolean isEquivalentProps(Section other, boolean shouldCompareCommonProps)
isEquivalentProps in class Sectionpublic static <T> DataDiffSection.Builder<T> create(SectionContext context)
public static <T> EventHandler<OnCheckIsSameContentEvent<T>> getOnCheckIsSameContentEventHandler(SectionContext context)
public static <T> EventHandler<OnCheckIsSameItemEvent<T>> getOnCheckIsSameItemEventHandler(SectionContext context)
public static <T> EventHandler<RenderEvent<T>> getRenderEventHandler(SectionContext context)
protected void generateChangeSet(SectionContext c, ChangeSet changeSet, SectionContext _prevScopedContext, Section _prevAbstractImpl, SectionContext _nextScopedContext, Section _nextAbstractImpl)
SectionLifecycleDiffSectionSpec method annotated with OnDiffgenerateChangeSet in class SectionLifecyclepublic boolean isDiffSectionSpec()
isDiffSectionSpec in class SectionLifecycleprotected java.lang.String verifyChangeSet(SectionContext context)
verifyChangeSet in class SectionLifecycle