Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(other-api/dev-v2): avoid ghost value creation #6756

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
- EddyVinck
- edgesoft
- edmundhung
- edzis
- efkann
- eldarshamukhamedov
- eltociear
Expand Down
6 changes: 3 additions & 3 deletions docs/other-api/dev-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ Luckily, there's a trick to get around this: use `global` as a cache for keeping
Here's a nifty utility adapted from [Jon Jensen's code][jenseng-code] for [his Remix Conf 2023 talk][jenseng-talk]:

```ts filename=app/utils/remember.ts
export function remember<T>(key: string, value: T) {
export function remember<T>(key: string, valueFactory: () => T) {
const g = global as any;
g.__singletons ??= {};
g.__singletons[key] ??= value;
g.__singletons[key] ??= valueFactory();
return g.__singletons[key];
}
```
Expand All @@ -234,7 +234,7 @@ import { PrismaClient } from "@prisma/client";
import { remember } from "~/utils/remember";

// hard-code a unique key so we can look up the client when this module gets re-imported
export const db = remember("db", new PrismaClient());
export const db = remember("db", () => new PrismaClient());
```

### How to set up MSW
Expand Down