sticky-module is a specialized JavaScript utility designed to guarantee that a given module is instantiated and evaluated only once, even across multiple imports or different bundling contexts within an application. It achieves this by storing and retrieving module instances using a unique, Symbol-based key, effectively creating an application-wide singleton for that module. This mechanism is particularly useful for libraries or components that require strict single-instance behavior to maintain consistent state or prevent redundant setup in complex module graphs, micro-frontends, or scenarios with multiple bundler outputs. The current stable version is 0.1.1. Its release cadence is likely slow, focusing on stability given its niche purpose. A key differentiator is its Symbol-based internal storage, which offers a robust and collision-resistant approach to global module caching compared to string-based keys.
npm install sticky-moduleVerified import paths — ran on the pinned version, not inferred.
Demonstrates how sticky-module ensures a module is initialized only once, returning the original instance on subsequent calls.
Be mindful of what data you store in 'sticky' modules. Ensure large objects are managed appropriately or consider if this pattern is suitable for your use case if memory pressure is a concern.
Do not assume global singleton behavior across distinct JavaScript realms. If cross-realm singletons are required, an alternative inter-realm communication or shared memory solution is needed.
Pin to exact versions or use care when upgrading, especially when a 1.0.0 release is made available. Review release notes thoroughly for any breaking changes.
Ensure you are using `import stickyModule from 'sticky-module';` in an ESM context. If using CommonJS, check your build tools for proper ESM-to-CJS interop or consider using dynamic import `import('sticky-module').then(m => m.default)`.Use the correct default import syntax: `import stickyModule from 'sticky-module';`. If in TypeScript, ensure `"esModuleInterop": true` and `"allowSyntheticDefaultImports": true` are set in your `tsconfig.json`.
No dependency data recorded yet.