refactor: use interfaces for function params
This commit is contained in:
@@ -128,10 +128,17 @@ export async function getParticle(docPath: string): Promise<Particle | null> {
|
||||
return doc.data();
|
||||
}
|
||||
|
||||
export interface GetParticleChildrenOptions {
|
||||
orderByField: string;
|
||||
orderDirection: "asc" | "desc";
|
||||
}
|
||||
|
||||
export async function getParticleChildren(
|
||||
collectionPath: string,
|
||||
orderByField: string = "created_at",
|
||||
orderDirection: "asc" | "desc" = "asc",
|
||||
{
|
||||
orderByField = "created_at",
|
||||
orderDirection = "asc",
|
||||
}: GetParticleChildrenOptions = { orderByField: "created_at", orderDirection: "asc" },
|
||||
): Promise<Particle[]> {
|
||||
const q = query(
|
||||
typedCollection(collectionPath),
|
||||
@@ -141,16 +148,29 @@ export async function getParticleChildren(
|
||||
return snap.docs.map((d) => d.data());
|
||||
}
|
||||
|
||||
export interface SubscribeToParticleChildrenOptions {
|
||||
onData: (children: Particle[]) => void;
|
||||
onError: (error: Error) => void;
|
||||
visibilityScopes?: string[];
|
||||
orderByField?: string;
|
||||
orderDirection?: "asc" | "desc";
|
||||
onAdded?: (child: Particle) => void;
|
||||
onRemoved?: (child: Particle, updatedChildren: Particle[]) => void;
|
||||
whereFilter?: QueryFieldFilterConstraint;
|
||||
}
|
||||
|
||||
export function subscribeToParticleChildren(
|
||||
collectionPath: string,
|
||||
onData: (children: Particle[]) => void,
|
||||
onError: (error: Error) => void,
|
||||
visibilityScopes: string[] = [],
|
||||
orderByField: string = "created_at",
|
||||
orderDirection: "asc" | "desc" = "desc",
|
||||
onAdded?: (child: Particle) => void,
|
||||
onRemoved?: (child: Particle, updatedChildren: Particle[]) => void,
|
||||
whereFilter?: QueryFieldFilterConstraint,
|
||||
{
|
||||
onData,
|
||||
onError,
|
||||
visibilityScopes = [],
|
||||
orderByField = "created_at",
|
||||
orderDirection = "desc",
|
||||
onAdded,
|
||||
onRemoved,
|
||||
whereFilter,
|
||||
}: SubscribeToParticleChildrenOptions
|
||||
): Unsubscribe {
|
||||
let q = query(typedCollection(collectionPath), orderBy(orderByField, orderDirection));
|
||||
if (visibilityScopes.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user