-
Notifications
You must be signed in to change notification settings - Fork 37
ListStore Guide: Adding a new list (WIP)
This guide is currently WIP and its contents might change significantly while the rest of the guide is fleshed out. If you have any questions/feedback, please reach out to @oguzkocer.
Table of Contents // TODO: Add links for each page
- Introduction
- Most important component: The
ListDescriptor
- How to consume an existing list
- How to implement a new list
- Sectioning (link added in consumption)
- Consider this! (Common gotchas)
- Internals
Before reading this guide, please make sure you have read both Introduction and Consuming a list pages. Even if you don't intend to implement the consumption part of a feature, it's still important to think about how something is going to be consumed before implementing the internals of it.
To add a new list to ListStore
, we have quite a few things to implement, but by design these are all fairly simple. Here is a checklist you should copy into your issue and follow along:
You MUST implement the following:
- Implement a
ListDescriptor
as discussed inListDescriptor
page. You MUST implement auniqueIdentifier
andtypeIdentifier
for yourListDescriptor
or a lot of weird things might happen. This is very important, so please ask for help if anything is not clear about it. - Implement a way to fetch a list given a
ListDescriptor
and anoffset
. This will be necessary to consume a list inListItemDataSourceInterface.fetchList
- When the list is fetched, dispatch
FETCHED_LIST_ITEMS
action. You'll need to pass the following parameters to this action: theListDescriptor
, remote item ids asList<Long>
, whether you loaded more data (or fetched the first page) asboolean
and if there is more data to be loaded asboolean
. We might consider getting rid of this requirement in the future in favor of using a coroutine for fetching the list. - Implement a way to fetch a single item. If you can implement a way to fetch a list of items (given their ids) that'd be even better. This will be necessary to consume a list in
ListItemDataSourceInterface.getItemsAndFetchIfNecessary
.
Good to have:
- If you need the UI to reload its data from the DB (and you need a central way to control this) use
LIST_DATA_INVALIDATED
action. An example would be when you fetch missing items from remote or downloaded the media of a post etc. - When individual items are removed, use
LIST_ITEMS_REMOVED
action which will remove given ids from all the lists for thatListDescriptorTypeIdentifier
- If you need all the lists for a certain
ListDescriptorTypeIdentifier
to re-fetch their ids from network, useLIST_REQUIRES_REFRESH
action. All activePagedListWrapper
s listen for this event and triggerfetchFirstPage
if theirListDescriptorTypeIdentifier
matches the action's.