1.0.2 • Published 8 months ago

@epic-web/remember v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago
npm install @epic-web/remember

Build Status GPL 3.0 License Code of Conduct

The problem

You're using a framework like Remix with --manual mode and re-evaluating your modules on every change. But you have some state that you don't want to lose between changes. For example:

  • Database connections
  • In-memory caches

This solution

This was copy/paste/modified/tested from @jenseng's abuse-the-platform demo (ISC). It's basically a type-safe singleton implementation that you can use to keep state between module re-evaluations.

Usage

import { remember } from '@epic-web/remember'

export const prisma = remember('prisma', () => new PrismaClient())

Keep in mind that any changes you make within that callback will not be reflected when the module is re-evaluated (that's the whole point). So if you need to change the callback, then you'll need to restart your server.

License

MIT

Credit

The original code was written by @jenseng and then I modified it and published it to fit my needs.