const toFamilyId = (projectId: string, type?: CustomerTypeValue) =>
projectId + (type ? `-${type}` : '');
const fromFamilyId = (queryKey: string) => {
const [projectId, type] = queryKey.split('-');
return {
projectId: projectId as string,
type: type ? (Number.parseInt(type, 10) as CustomerTypeValue) : undefined
};
};
const customersAtom = Atom.family((id: string) =>
runtime
.atom(
Effect.gen(function* () {
const { projectId, type } = fromFamilyId(id);
const vrpc = yield* VRpc;
const customers = yield* vrpc('ListCustomers', {
projectId
});
return customers.filter((customer) =>
type ? customer.type === type : true
);
})
)
.pipe(Atom.withReactivity(queryKeys.customer.all))
);
const toFamilyId = (projectId: string, type?: CustomerTypeValue) =>
projectId + (type ? `-${type}` : '');
const fromFamilyId = (queryKey: string) => {
const [projectId, type] = queryKey.split('-');
return {
projectId: projectId as string,
type: type ? (Number.parseInt(type, 10) as CustomerTypeValue) : undefined
};
};
const customersAtom = Atom.family((id: string) =>
runtime
.atom(
Effect.gen(function* () {
const { projectId, type } = fromFamilyId(id);
const vrpc = yield* VRpc;
const customers = yield* vrpc('ListCustomers', {
projectId
});
return customers.filter((customer) =>
type ? customer.type === type : true
);
})
)
.pipe(Atom.withReactivity(queryKeys.customer.all))
);