Skip to content

Commit

Permalink
swap singleton for @epic-web/remember
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Sep 10, 2023
1 parent ea6109f commit bd84568
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions app/utils/cache.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { LRUCache } from 'lru-cache'
import { z } from 'zod'
import { updatePrimaryCacheValue } from '#app/routes/admin+/cache_.sqlite.tsx'
import { getInstanceInfo, getInstanceInfoSync } from './litefs.server.ts'
import { singleton } from './singleton.server.ts'
import { remember } from '@epic-web/remember'

Check warning on line 16 in app/utils/cache.server.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

`@epic-web/remember` import should occur before import of `better-sqlite3`
import { cachifiedTimingReporter, type Timings } from './timing.server.ts'

const CACHE_DATABASE_PATH = process.env.CACHE_DATABASE_PATH

const cacheDb = singleton('cacheDb', createDatabase)
const cacheDb = remember('cacheDb', createDatabase)

function createDatabase(tryAgain = true): Database.Database {
const db = new Database(CACHE_DATABASE_PATH)
Expand Down Expand Up @@ -47,7 +47,7 @@ function createDatabase(tryAgain = true): Database.Database {
return db
}

const lru = singleton(
const lru = remember(
'lru-cache',
() => new LRUCache<string, CacheEntry<unknown>>({ max: 5000 }),
)
Expand Down
2 changes: 1 addition & 1 deletion app/utils/client-hints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useRevalidator } from '@remix-run/react'
import * as React from 'react'
import { useRequestInfo } from './request-info.ts'

export const clientHints = {
const clientHints = {
theme: {
cookieName: 'CH-prefers-color-scheme',
getValueCode: `window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'`,
Expand Down
6 changes: 2 additions & 4 deletions app/utils/db.server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PrismaClient } from '@prisma/client'
import chalk from 'chalk'
import { singleton } from './singleton.server.ts'
import { remember } from '@epic-web/remember'

Check warning on line 3 in app/utils/db.server.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

`@epic-web/remember` import should occur before import of `@prisma/client`

const prisma = singleton('prisma', () => {
export const prisma = remember('prisma', () => {
// NOTE: if you change anything in this function you'll need to restart
// the dev server to see your changes.

Expand Down Expand Up @@ -34,5 +34,3 @@ const prisma = singleton('prisma', () => {
client.$connect()
return client
})

export { prisma }
10 changes: 0 additions & 10 deletions app/utils/singleton.server.ts

This file was deleted.

6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"dependencies": {
"@conform-to/react": "^0.8.0",
"@conform-to/zod": "^0.8.0",
"@epic-web/remember": "^1.0.0",
"@epic-web/totp": "^1.0.6",
"@paralleldrive/cuid2": "^2.2.2",
"@prisma/client": "^5.1.1",
Expand Down

0 comments on commit bd84568

Please sign in to comment.