loading code fetching the highlighted snippet
Each complete source is highlighted before composing character, word, or line diffs. Comments and strings keep their syntax context. Register only the languages you use.
type User = { name: string; active: boolean }
export function loadTeam(ids: string[]): Promise<User[]> {
// Fetch each teammate, then keep the active ones.
return Promise.all(ids.map(id =>
fetch('/api/users/' + id).then(res => res.json())
)).then(users => users.filter(user => user.active));
export async function loadTeam(ids: string[]): Promise<User[]> {
// Fetch in parallel; fail early on a bad response.
const users = await Promise.all(ids.map(async id => {
const res = await fetch(`/api/users/${encodeURIComponent(id)}`);
if (!res.ok) throw new Error(`User ${id}: ${res.status}`);
return await res.json() as User;
}));
return users.filter(({ active }) => active);
}