-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parallel and sequential fething updates
- Loading branch information
Showing
12 changed files
with
100 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Stack } from "@/components/primitives/stack"; | ||
import { Text } from "@/components/typography/text"; | ||
import { FC, PropsWithChildren } from "react"; | ||
|
||
type Props = { | ||
title: string; | ||
} & PropsWithChildren; | ||
|
||
export const BasicList: FC<Props> = (props) => { | ||
return ( | ||
<Stack> | ||
<Text>{props.title}</Text> | ||
<Stack className="max-h-[200px] overflow-scroll p-md border-4"> | ||
{props.children} | ||
</Stack> | ||
</Stack> | ||
); | ||
}; |
5 changes: 0 additions & 5 deletions
5
apps/bible/app/bible/data-fetching/parrallel-and-sequential/components/bad-example.tsx
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
apps/bible/app/bible/data-fetching/parrallel-and-sequential/components/good-example.tsx
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
apps/bible/app/bible/data-fetching/parrallel-and-sequential/components/parallel-fetching.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { getTodos } from "@/app/api/todo"; | ||
import { getUsers } from "@/app/api/users"; | ||
import { DisplayTodos } from "@/app/todos/components/display-todos"; | ||
import { DisplayUsers } from "@/app/user/components/display-users"; | ||
import { Stack } from "@/components/primitives/stack"; | ||
|
||
export const ParrallelFetching = async () => { | ||
const todosPromise = getTodos("parallel example"); | ||
const usersPromise = getUsers("parrallel example"); | ||
const [todos, users] = await Promise.all([todosPromise, usersPromise]); | ||
|
||
// One more bad example | ||
// const todos = await getTodos("good example"); | ||
// const users = await getUsers("good example"); | ||
|
||
return ( | ||
<Stack> | ||
<DisplayTodos todos={todos.todos} /> | ||
<DisplayUsers users={users.users} /> | ||
</Stack> | ||
); | ||
}; |
5 changes: 5 additions & 0 deletions
5
...bible/app/bible/data-fetching/parrallel-and-sequential/components/sequential-fetching.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ShowTodosWithUsers } from "@/app/todos/components/show-todos-with-users"; | ||
|
||
export const SequentialFetching = () => { | ||
return <ShowTodosWithUsers />; | ||
}; |
14 changes: 7 additions & 7 deletions
14
apps/bible/app/bible/data-fetching/parrallel-and-sequential/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,14 @@ | ||
import { getTodos } from "@/app/api/todo"; | ||
import { getUsers } from "@/app/api/users"; | ||
import { BasicList } from "@/app/_templates/basic-list"; | ||
import { GetTodosResponse, getTodos } from "@/app/api/todo"; | ||
import { Todo } from "@/app/todo/components/todo"; | ||
import { DisplayUsers } from "@/app/user/components/display-users"; | ||
import { Stack } from "@/components/primitives/stack"; | ||
import { Text } from "@/components/typography/text"; | ||
|
||
export const DisplayTodos = async () => { | ||
const todosPromise = getTodos("good example"); | ||
const usersPromise = getUsers("good example"); | ||
const [todos, users] = await Promise.all([todosPromise, usersPromise]); | ||
|
||
// One more bad example | ||
// const todos = await getTodos("good example"); | ||
// const users = await getUsers("good example"); | ||
import { FC } from "react"; | ||
|
||
export const DisplayTodos: FC<GetTodosResponse> = ({ todos }) => { | ||
return ( | ||
<Stack> | ||
<Text>Todos:</Text> | ||
<Stack className="max-h-[200px] overflow-scroll p-md border-4"> | ||
{todos.todos.map((todo) => ( | ||
<Todo key={todo.id} {...todo} /> | ||
))} | ||
</Stack> | ||
<DisplayUsers users={users.users} /> | ||
</Stack> | ||
<BasicList title="Todos:"> | ||
{todos.map((todo) => ( | ||
<Todo key={todo.id} {...todo} /> | ||
))} | ||
</BasicList> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { BasicList } from "@/app/_templates/basic-list"; | ||
import { getTodos } from "@/app/api/todo"; | ||
import { Todo } from "@/app/todo/components/todo"; | ||
import { ShowUsers } from "@/app/user/components/show-users"; | ||
import { Stack } from "@/components/primitives/stack"; | ||
|
||
export const ShowTodosWithUsers = async () => { | ||
const { todos } = await getTodos("sequential example"); | ||
return ( | ||
<Stack> | ||
<BasicList title="Todos:"> | ||
{todos.map((todo) => ( | ||
<Todo key={todo.id} {...todo} /> | ||
))} | ||
</BasicList> | ||
<ShowUsers /> | ||
</Stack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
import { BasicList } from "@/app/_templates/basic-list"; | ||
import { getTodos } from "@/app/api/todo"; | ||
import { Todo } from "@/app/todo/components/todo"; | ||
import { ShowUsers } from "@/app/user/components/show-users"; | ||
import { Stack } from "@/components/primitives/stack"; | ||
import { Text } from "@/components/typography/text"; | ||
|
||
export const ShowTodos = async () => { | ||
const { todos } = await getTodos("bad example"); | ||
const { todos } = await getTodos("sequential example"); | ||
return ( | ||
<Stack> | ||
<Text>Todos:</Text> | ||
<Stack className="max-h-[200px] overflow-scroll p-md border-4"> | ||
{todos.map((todo) => ( | ||
<Todo key={todo.id} {...todo} /> | ||
))} | ||
</Stack> | ||
<ShowUsers /> | ||
</Stack> | ||
<BasicList title="Todos:"> | ||
{todos.map((todo) => ( | ||
<Todo key={todo.id} {...todo} /> | ||
))} | ||
</BasicList> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
import { GetUserResponse } from "@/app/api/users"; | ||
import { Stack } from "@/components/primitives/stack"; | ||
import { Text } from "@/components/typography/text"; | ||
import { User } from "./user"; | ||
import { FC } from "react"; | ||
import { BasicList } from "@/app/_templates/basic-list"; | ||
|
||
export const DisplayUsers: FC<GetUserResponse> = ({ users }) => { | ||
return ( | ||
<Stack> | ||
<Text>Users:</Text> | ||
<Stack className="max-h-[200px] overflow-scroll p-md border-4"> | ||
{users.map((user) => ( | ||
<User key={user.id} {...user} /> | ||
))} | ||
</Stack> | ||
</Stack> | ||
<BasicList title="Users:"> | ||
{users.map((user) => ( | ||
<User key={user.id} {...user} /> | ||
))} | ||
</BasicList> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
import { getUsers } from "@/app/api/users"; | ||
import { Stack } from "@/components/primitives/stack"; | ||
import { Text } from "@/components/typography/text"; | ||
import { User } from "./user"; | ||
import { BasicList } from "@/app/_templates/basic-list"; | ||
|
||
export const ShowUsers = async () => { | ||
const { users } = await getUsers("bad exmaple"); | ||
return ( | ||
<Stack> | ||
<Text>Users:</Text> | ||
<Stack className="max-h-[200px] overflow-scroll p-md border-4"> | ||
{users.map((user) => ( | ||
<User key={user.id} {...user} /> | ||
))} | ||
</Stack> | ||
</Stack> | ||
<BasicList title="Users:"> | ||
{users.map((user) => ( | ||
<User key={user.id} {...user} /> | ||
))} | ||
</BasicList> | ||
); | ||
}; |