-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: refactor unfinished * feat: support create router * refactor: render mode * fix: code splitting false * feat: add location for icestark * chore: remove console * test: examples * fix: dataloader is undefined * fix: test * fix: test case * fix: test case * fix: types * fix: test case * fix: lock * feat: async data loader * fix: update lock * fix: hydration * fix: router * fix: router * chore: log * fix: hmr * fix: test * fix: test * feat: await * fix: await component * fix: lint * refactor: type * fix: type * fix: app data loader * fix: test * fix: test * test: async data * test: async data * docs: async data loader * fix: lint * refactor: loader config * fix: test * fix: compat with old useage --------- Co-authored-by: ClarkXia <[email protected]>
- Loading branch information
1 parent
7588052
commit f56497f
Showing
15 changed files
with
451 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useData, defineDataLoader, Await } from 'ice'; | ||
import styles from './index.module.css'; | ||
|
||
export default function Home() { | ||
const data = useData(); | ||
|
||
return ( | ||
<> | ||
<h2 className={styles.title}>With dataLoader</h2> | ||
<Await resolve={data} fallback={<p>Loading item info...</p>} errorElement={<p>Error loading!</p>}> | ||
{(itemInfo) => { | ||
return <p>Item id is <span id="itemId">{itemInfo.id}</span></p>; | ||
}} | ||
</Await> | ||
</> | ||
); | ||
} | ||
|
||
export function pageConfig() { | ||
return { | ||
title: 'Home', | ||
}; | ||
} | ||
|
||
export const dataLoader = defineDataLoader(async () => { | ||
const promise = new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve({ | ||
id: 1233, | ||
}); | ||
}, 100); | ||
}); | ||
return await promise; | ||
}, { defer: true }); | ||
|
52 changes: 52 additions & 0 deletions
52
examples/with-data-loader/src/pages/with-defer-loaders.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,52 @@ | ||
import { useData, defineDataLoader, Await } from 'ice'; | ||
import styles from './index.module.css'; | ||
|
||
export default function Home() { | ||
const data = useData(); | ||
|
||
return ( | ||
<> | ||
<h2 className={styles.title}>With dataLoader</h2> | ||
<Await resolve={data[0]} fallback={<p>Loading item info...</p>} errorElement={<p>Error loading!</p>}> | ||
{(itemInfo) => { | ||
return <p>Item id is {itemInfo.id}</p>; | ||
}} | ||
</Await> | ||
<Await resolve={data[1]} fallback={<p>Loading item info...</p>} errorElement={<p>Error loading!</p>}> | ||
{(itemInfo) => { | ||
return <p>Item price is {itemInfo.price}</p>; | ||
}} | ||
</Await> | ||
</> | ||
); | ||
} | ||
|
||
export function pageConfig() { | ||
return { | ||
title: 'Home', | ||
}; | ||
} | ||
|
||
export const dataLoader = defineDataLoader([ | ||
async () => { | ||
const promise = new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve({ | ||
id: 1233, | ||
}); | ||
}, 100); | ||
}); | ||
return await promise; | ||
}, | ||
async () => { | ||
const promise = new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve({ | ||
price: 9.99, | ||
}); | ||
}, 2000); | ||
}); | ||
return await promise; | ||
}, | ||
], { defer: true }); | ||
|
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,45 @@ | ||
import { useData, defineDataLoader, defineServerDataLoader, Await } from 'ice'; | ||
import styles from './index.module.css'; | ||
|
||
export default function Home() { | ||
const data = useData(); | ||
|
||
return ( | ||
<> | ||
<h2 className={styles.title}>With dataLoader</h2> | ||
<Await resolve={data} fallback={<p>Loading item info...</p>} errorElement={<p>Error loading!</p>}> | ||
{(itemInfo) => { | ||
return <p>Item id is {itemInfo.id}</p>; | ||
}} | ||
</Await> | ||
</> | ||
); | ||
} | ||
|
||
export function pageConfig() { | ||
return { | ||
title: 'Home', | ||
}; | ||
} | ||
|
||
export const dataLoader = defineDataLoader(async () => { | ||
const promise = new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve({ | ||
id: 1233, | ||
}); | ||
}, 100); | ||
}); | ||
return await promise; | ||
}, { defer: true }); | ||
|
||
export const serverDataLoader = defineServerDataLoader(async () => { | ||
const promise = new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve({ | ||
id: 1233, | ||
}); | ||
}, 100); | ||
}); | ||
return await promise; | ||
}); |
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
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
Oops, something went wrong.