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,
Section _prevAbstractImpl,
Section _nextAbstractImpl)
This method will delegate to the
DiffSectionSpec method annotated with OnDiff |
static EventHandler |
getOnCheckIsSameContentEventHandler(SectionContext context) |
static EventHandler |
getOnCheckIsSameItemEventHandler(SectionContext context) |
static EventHandler |
getRenderEventHandler(SectionContext context) |
boolean |
isDiffSectionSpec() |
boolean |
isEquivalentTo(Section other)
Compares this section to a different one to check if they are the same
|
generateUniqueGlobalKeyForChild, getChildren, getEventDispatcher, getGlobalKey, getHandle, getKey, getLogTag, getParent, getScopedContext, getSimpleName, getStateContainer, makeShallowCopy, makeShallowCopy, recordEventTrigger, setChildren, setCount, setGlobalKey, setKey, setScopedContextacceptTriggerEvent, bindService, createChildren, createInitialState, createService, dataBound, dataRendered, dispatchLoadingEvent, dispatchOnEvent, getEventTrigger, getEventTrigger, getLoadingEventHandler, getService, getTreePropsForChildren, isSectionIndexValid, newEventHandler, newEventHandler, newEventTrigger, populateTreeProps, refresh, requestFocus, requestFocus, requestFocus, requestFocusWithOffset, requestFocusWithOffset, requestFocusWithOffset, requestSmoothFocus, requestSmoothFocus, requestSmoothFocus, shouldUpdate, transferService, transferState, unbindService, viewportChangedpublic boolean isEquivalentTo(Section other)
SectionThis is used to be able to skip rendering a section again. We avoid using the Object.equals(Object) so we can optimize the code better over time since we don't have to
adhere to the contract required for a equals method.
isEquivalentTo in interface Equivalence<Section>isEquivalentTo in class Sectionother - the component to compare topublic static <T> DataDiffSection.Builder<T> create(SectionContext context)
public static EventHandler getOnCheckIsSameContentEventHandler(SectionContext context)
public static EventHandler getOnCheckIsSameItemEventHandler(SectionContext context)
public static EventHandler getRenderEventHandler(SectionContext context)
protected void generateChangeSet(SectionContext c, ChangeSet changeSet, Section _prevAbstractImpl, Section _nextAbstractImpl)
SectionLifecycleDiffSectionSpec method annotated with OnDiffgenerateChangeSet in class SectionLifecyclepublic boolean isDiffSectionSpec()
isDiffSectionSpec in class SectionLifecycle