Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@epic-web/remember

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@epic-web/remember

Simple, type-safe, "singleton" implementation.

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
19K
increased by2.6%
Maintainers
2
Weekly downloads
 
Created
Source

🤔 @epic-web/remember

Simple, type-safe, "singleton" implementation.

For when your "hot module replacement" involves re-evaluating a module, but you don't want to actually re-evaluate a portion of it.

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.

Forget a value

It might be required to explicitly forget a value if it gets outdated, a memorized connection gets lost or memorized instance closes/errors/etc.

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

export const server = remember('server', () =>
    http.createServer().listen('8080')
        .on('close', () => forget('server')))

License

MIT

Credit

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

FAQs

Package last updated on 29 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc