Lists API
The Lists API (dcupl.lists) provides methods for creating and managing isolated data collections with their own filters, queries, and state management.
Overview
Lists are isolated views of your data that maintain their own query state and provide access to the catalog API for querying, filtering, and analytics. Each list operates independently and can have different filters applied to the same underlying data model.
Methods
create()
Creates a new list instance.
Signature:
create<T>(config: DcuplListOptions): DcuplList<T>Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
config |
DcuplListOptions |
Yes | List configuration options |
Returns: DcuplList - The created list instance
Examples:
const productList = dcupl.lists.create({
modelKey: 'Product',
});const activeProducts = dcupl.lists.create({
modelKey: 'Product',
listKey: 'activeProducts',
});const selectedProducts = dcupl.lists.create({
modelKey: 'Product',
listItemKeys: ['p1', 'p2', 'p3'],
});const expensiveProducts = dcupl.lists.create({
modelKey: 'Product',
query: {
modelKey: 'Product',
queries: [{ operator: 'gte', attribute: 'price', value: 100 }],
},
});const list = dcupl.lists.create({
modelKey: 'Product',
autoUpdate: true,
});get()
Retrieves a list by its key.
Signature:
get(listKey: string): DcuplList | undefinedParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
listKey |
string |
Yes | The key of the list to retrieve |
Returns: DcuplList | undefined - The list instance or undefined if not found
Examples:
const list = dcupl.lists.get('activeProducts');
if (list) {
const items = list.catalog.query.items();
}const exists = dcupl.lists.get('myList') !== undefined;const list = dcupl.lists.get('myList');
if (list) {
// Use list
} else {
// Create list
const newList = dcupl.lists.create({
modelKey: 'Product',
listKey: 'myList',
});
}getAll()
Retrieves all lists or filters by model.
Signature:
getAll(filter?: { modelKey: string }): DcuplList[]Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
filter |
{ modelKey: string } |
No | Optional filter by model key |
Returns: DcuplList[] - Array of list instances
Examples:
const allLists = dcupl.lists.getAll();
console.log(allLists.length);const productLists = dcupl.lists.getAll({ modelKey: 'Product' });dcupl.lists.getAll().forEach((list) => {
list.update();
});const listsByModel = {};
dcupl.lists.getAll().forEach((list) => {
listsByModel[list.modelKey] = (listsByModel[list.modelKey] || 0) + 1;
});destroy()
Destroys lists and cleans up resources.
Signature:
destroy(options?: { listKey?: string; modelKey?: string }): voidParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
object |
No | Destroy options (all lists if omitted) |
options.listKey |
string |
No | Specific list key to destroy |
options.modelKey |
string |
No | Destroy all lists for a model |
Examples:
dcupl.lists.destroy({ listKey: 'activeProducts' });dcupl.lists.destroy({ modelKey: 'Product' });dcupl.lists.destroy();const list = dcupl.lists.get('myList');
if (list) {
dcupl.lists.destroy({ listKey: 'myList' });
}DcuplList Class
The DcuplList class represents an individual list instance with its own state and catalog API.
Properties
key
The unique identifier for this list.
Type: string
Example:
const list = dcupl.lists.create({
modelKey: 'Product',
listKey: 'myList',
});
console.log(list.key); // 'myList'modelKey
The model this list is based on.
Type: string
Example:
console.log(list.modelKey); // 'Product'catalog
Access to the catalog API for querying and analytics.
Type: Catalog
Example:
const items = list.catalog.query.items();
const facets = list.catalog.fn.facets({ attribute: 'category' });Methods
update()
Updates the list with the latest data and reprocesses queries.
Signature:
update(options?: { reprocessData?: boolean }): voidParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options |
object |
No | Update options |
options.reprocessData |
boolean |
No | Force full data reprocessing |
Examples:
list.update();list.update({ reprocessData: true });dcupl.data.update([{ key: 'p1', price: 150 }], { model: 'Product' });
await dcupl.update();
list.update(); // Update list to reflect changesconst list = dcupl.lists.create({
modelKey: 'Product',
autoUpdate: true
});
// List automatically updates when data changes
dcupl.data.update([...], { model: 'Product' });
await dcupl.update(); // List updates automaticallydestroy()
Destroys the list and cleans up resources.
Signature:
destroy(): voidExamples:
const list = dcupl.lists.create({ modelKey: 'Product' });
list.destroy();class MyComponent {
private list: DcuplList;
constructor() {
this.list = dcupl.lists.create({ modelKey: 'Product' });
}
destroy() {
this.list.destroy();
}
}on()
Subscribes to change events from the list.
Signature:
on(callback: CallbackFunction): () => voidParameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
callback |
CallbackFunction |
Yes | Function to call on changes |
Returns: () => void - Unsubscribe function
Examples:
const unsubscribe = list.on((message) => {
console.log('List changed:', message);
});unsubscribe();list.on((message) => {
if (message.type === 'list_updated') {
console.log('List was updated');
}
if (message.type === 'query_apply') {
console.log('Query was applied');
}
});const unsub1 = list.on(callback1);
const unsub2 = list.on(callback2);
// Cleanup
unsub1();
unsub2();Configuration Types
DcuplListOptions
Configuration options for creating a list.
Type Definition:
type DcuplListOptions = {
modelKey: string;
listKey?: string;
listItemKeys?: string[];
query?: DcuplGlobalQueryOptions;
autoUpdate?: boolean;
};Properties:
| Property | Type | Required | Description |
|---|---|---|---|
modelKey |
string |
Yes | Model this list is based on |
listKey |
string |
No | Unique list identifier (auto-generated if omitted) |
listItemKeys |
string[] |
No | Specific item keys to include |
query |
DcuplGlobalQueryOptions |
No | Initial query to apply |
autoUpdate |
boolean |
No | Auto-update when data changes |
Examples:
{
modelKey: 'Product';
}{
modelKey: 'Product',
listKey: 'featuredProducts'
}{
modelKey: 'Product',
listItemKeys: ['p1', 'p2', 'p3']
}{
modelKey: 'Product',
query: {
modelKey: 'Product',
queries: [
{ operator: 'eq', attribute: 'status', value: 'active' }
]
}
}{
modelKey: 'Product',
listKey: 'activeProducts',
autoUpdate: true
}Common Patterns
Filtered List Pattern
Create lists with pre-applied filters for common queries.
const activeProducts = dcupl.lists.create({
modelKey: 'Product',
listKey: 'activeProducts',
query: {
modelKey: 'Product',
queries: [{ operator: 'eq', attribute: 'status', value: 'active' }],
},
});const featuredProducts = dcupl.lists.create({
modelKey: 'Product',
listKey: 'featuredProducts',
query: {
modelKey: 'Product',
queries: [
{ operator: 'eq', attribute: 'featured', value: true },
{ operator: 'eq', attribute: 'status', value: 'active' },
],
},
});Master-Detail Pattern
Create lists that work together for master-detail views.
const categoriesList = dcupl.lists.create({
modelKey: 'Category',
listKey: 'categories',
});const categoryProducts = dcupl.lists.create({
modelKey: 'Product',
listKey: 'categoryProducts',
});function selectCategory(categoryKey: string) {
categoryProducts.catalog.query.setCondition({
operator: 'eq',
attribute: 'category',
value: { key: categoryKey },
});
}Search Results Pattern
Create a list for search results that can be updated dynamically.
const searchResults = dcupl.lists.create({
modelKey: 'Product',
listKey: 'searchResults',
});function search(query: string) {
if (query.length === 0) {
searchResults.catalog.query.clear();
} else {
searchResults.catalog.query.setCondition({
operator: 'find',
attribute: 'name',
value: query,
options: { transform: ['lowercase'] },
});
}
return searchResults.catalog.query.items();
}Faceted Search Pattern
Create lists with dynamic facet-based filtering.
const productSearch = dcupl.lists.create({
modelKey: 'Product',
listKey: 'productSearch',
});const categories = productSearch.catalog.fn.facets({
attribute: 'category',
});function filterByCategory(categoryKey: string) {
productSearch.catalog.query.addCondition({
operator: 'eq',
attribute: 'category',
value: { key: categoryKey },
queryKey: 'category',
});
}function clearCategoryFilter() {
productSearch.catalog.query.removeCondition({
queryKey: 'category',
});
}Pagination Pattern
Create lists with pagination support.
const productList = dcupl.lists.create({
modelKey: 'Product',
});
const pageSize = 20;
let currentPage = 0;
function getPage(page: number) {
currentPage = page;
return productList.catalog.query.items({
start: page * pageSize,
count: pageSize,
});
}
function getTotalPages() {
const total = productList.catalog.query.count();
return Math.ceil(total / pageSize);
}
function nextPage() {
return getPage(currentPage + 1);
}
function prevPage() {
return getPage(Math.max(0, currentPage - 1));
}Multiple Filter Groups Pattern
Create complex filters with multiple grouped conditions.
const productList = dcupl.lists.create({
modelKey: 'Product',
});
// Price range filter
productList.catalog.query.addGroup({
groupKey: 'priceRange',
groupType: 'and',
queries: [
{ operator: 'gte', attribute: 'price', value: 50 },
{ operator: 'lte', attribute: 'price', value: 200 },
],
});
// Category filter
productList.catalog.query.addGroup({
groupKey: 'categories',
groupType: 'or',
queries: [
{ operator: 'eq', attribute: 'category', value: { key: 'cat1' } },
{ operator: 'eq', attribute: 'category', value: { key: 'cat2' } },
],
});
// Remove specific group
productList.catalog.query.removeGroup('priceRange');Subset List Pattern
Create a list from specific items.
const mainList = dcupl.lists.create({ modelKey: 'Product' });
const allProducts = mainList.catalog.query.items();const selectedKeys = ['p1', 'p5', 'p10'];
const selectionList = dcupl.lists.create({
modelKey: 'Product',
listKey: 'selection',
listItemKeys: selectedKeys,
});const selectedItems = selectionList.catalog.query.items();Auto-Update Pattern
Lists that automatically update when data changes.
const dcupl = new Dcupl({
performance: {
autoUpdateLists: {
enabled: true,
},
},
});const autoList = dcupl.lists.create({
modelKey: 'Product',
});const alwaysAutoList = dcupl.lists.create({
modelKey: 'Product',
autoUpdate: true,
});const manualList = dcupl.lists.create({
modelKey: 'Product',
autoUpdate: false,
});dcupl.data.update([{ key: 'p1', price: 150 }], { model: 'Product' });
await dcupl.update();manualList.update();Complete Examples
Product Listing with Filters
// Create product list
const productList = dcupl.lists.create({
modelKey: 'Product',
listKey: 'products',
});
// Add filters
productList.catalog.query.addCondition([
{ operator: 'eq', attribute: 'status', value: 'active' },
{ operator: 'gte', attribute: 'price', value: 50 },
]);
// Get results with pagination
const products = productList.catalog.query.items({
start: 0,
count: 20,
sort: { price: 'asc' },
});
// Get facets for filtering UI
const categories = productList.catalog.fn.facets({
attribute: 'category',
});
// Update filter based on user selection
productList.catalog.query.addCondition({
operator: 'eq',
attribute: 'category',
value: { key: 'electronics' },
});Shopping Cart Implementation
// Create cart list
const cart = dcupl.lists.create({
modelKey: 'Product',
listKey: 'shoppingCart',
listItemKeys: [],
});
// Add item to cart
function addToCart(productKey: string) {
const currentKeys = cart.catalog.query.items().map((item) => item.key);
if (!currentKeys.includes(productKey)) {
currentKeys.push(productKey);
const newCart = dcupl.lists.create({
modelKey: 'Product',
listKey: 'shoppingCart',
listItemKeys: currentKeys,
});
}
}
// Remove from cart
function removeFromCart(productKey: string) {
const currentKeys = cart.catalog.query
.items()
.map((item) => item.key)
.filter((key) => key !== productKey);
dcupl.lists.destroy({ listKey: 'shoppingCart' });
const newCart = dcupl.lists.create({
modelKey: 'Product',
listKey: 'shoppingCart',
listItemKeys: currentKeys,
});
}
// Get cart total
function getCartTotal(): number {
const aggregation = cart.catalog.fn.aggregate({
attribute: 'price',
types: ['sum'],
});
return aggregation.sum || 0;
}Multi-List Dashboard
// Create multiple lists for dashboard
const allProducts = dcupl.lists.create({
modelKey: 'Product',
listKey: 'allProducts',
});
const newProducts = dcupl.lists.create({
modelKey: 'Product',
listKey: 'newProducts',
query: {
modelKey: 'Product',
queries: [{ operator: 'gte', attribute: 'createdAt', value: last30Days }],
},
});
const featuredProducts = dcupl.lists.create({
modelKey: 'Product',
listKey: 'featured',
query: {
modelKey: 'Product',
queries: [{ operator: 'eq', attribute: 'featured', value: true }],
},
});
// Get dashboard metrics
const metrics = {
total: allProducts.catalog.query.count(),
new: newProducts.catalog.query.count(),
featured: featuredProducts.catalog.query.count(),
averagePrice: allProducts.catalog.fn.aggregate({
attribute: 'price',
types: ['avg'],
}).avg,
};