-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add evictAll method * Add createSingleEntryCache convenience wrapper * Convert caches to use named parameters * Update tests and documentation
- Loading branch information
Showing
33 changed files
with
461 additions
and
91 deletions.
There are no files selected for viewing
File renamed without changes.
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
10 changes: 5 additions & 5 deletions
10
packages/suspense-website/src/examples/createCache/cache.ts
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,9 +1,9 @@ | ||
import { createCache } from "suspense"; | ||
|
||
export const userProfileCache = createCache<[userId: string], JSON>( | ||
async (userId: string) => { | ||
const response = await fetch(`https://example.com/user?id=${userId}`); | ||
export const userProfileCache = createCache<[userId: string], JSON>({ | ||
load: async (userId: string) => { | ||
const response = await fetch(`/api/user?id=${userId}`); | ||
const json = await response.json(); | ||
return json; | ||
} | ||
); | ||
}, | ||
}); |
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
11 changes: 6 additions & 5 deletions
11
packages/suspense-website/src/examples/createCache/cacheWithSignal.ts
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,17 +1,18 @@ | ||
import { CacheLoadOptions, createCache } from "suspense"; | ||
|
||
// REMOVE_BEFORE | ||
createCache<[userId: string], JSON>( | ||
async (userId: string, options: CacheLoadOptions) => { | ||
|
||
createCache<[userId: string], JSON>({ | ||
load: async (userId: string, options: CacheLoadOptions) => { | ||
// An AbortSignal is passed in as the final parameter with each request | ||
const { signal } = options; | ||
|
||
// The native fetch API supports AbortSignals | ||
// All that's required to support cancellation is to forward the signal | ||
const response = await fetch(`https://example.com/user?id=${userId}`, { | ||
const response = await fetch(`/api/user?id=${userId}`, { | ||
signal, | ||
}); | ||
const json = await response.json(); | ||
return json; | ||
} | ||
); | ||
}, | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/suspense-website/src/examples/createSingleEntryCache/cache.ts
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,9 @@ | ||
import { createSingleEntryCache } from "suspense"; | ||
|
||
const articlesCache = createSingleEntryCache<[], JSON>({ | ||
load: async () => { | ||
const response = await fetch(`/api/articles/?sort=DESC&limit=10`); | ||
const json = await response.json(); | ||
return json; | ||
}, | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/suspense-website/src/examples/createSingleEntryCache/cacheWithParameters.ts
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,13 @@ | ||
import { createSingleEntryCache } from "suspense"; | ||
|
||
class ApiClient { | ||
async getRecentArticles() { | ||
return JSON.parse(""); | ||
} | ||
} | ||
|
||
// REMOVE_BEFORE | ||
|
||
createSingleEntryCache<[ApiClient], JSON>({ | ||
load: async (client: ApiClient) => client.getRecentArticles(), | ||
}); |
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
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
32 changes: 32 additions & 0 deletions
32
packages/suspense-website/src/routes/api/createSingleEntryCache.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,32 @@ | ||
import Block from "../../components/Block"; | ||
import Container from "../../components/Container"; | ||
import Code from "../../components/Code"; | ||
import { createSingleEntryCache } from "../../examples"; | ||
import Header from "../../components/Header"; | ||
import { Link } from "react-router-dom"; | ||
import { CREATE_CACHE } from "../config"; | ||
|
||
export default function Route() { | ||
return ( | ||
<Container> | ||
<Block> | ||
<Header title="createSingleEntryCache" /> | ||
</Block> | ||
<Block> | ||
<p> | ||
Convenience wrapper around{" "} | ||
<code> | ||
<Link to={CREATE_CACHE}>createCache</Link> | ||
</code>{" "} | ||
for caches that only contain a single value. | ||
</p> | ||
<Code code={createSingleEntryCache.cache} /> | ||
<p> | ||
This type of cache can still accept parameters, although they won't be | ||
used to store the cached value. | ||
</p> | ||
<Code code={createSingleEntryCache.cacheWithParameters} /> | ||
</Block> | ||
</Container> | ||
); | ||
} |
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.
71f1029
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
suspense – ./
suspense.vercel.app
suspense-git-main-bvaughn.vercel.app
suspense-bvaughn.vercel.app
suspense-npm.vercel.app