weak-map-element-registry
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

weak-map-element-registry

This library first and foremost provides a WeakMap to store DOM elements being used in your application. Elements are stored and provide a reference to their root reference, which is stored as a separate entry. This entry can be used across multiple objects.

Usage

API

  1. element: DOM Node to observe
  2. options: Object (optional)
    • list of options to set as unique key to retrieve under root
import WeakMapElementRegistry from 'weak-map-element-registry';

const observerOptions = { root, rootMargin: '0px 0px 100px 0px', threshold: 0 };
const options = Object.assign({}, observerOptions, { scrollableArea: '.my-list' });
weakMapElementRegistry.addElement(element, options);

// Use in cleanup lifecycle hooks (if applicable) from the element being observed
weakMapElementRegistry.removeElement(element, observerOptions);

// Use in cleanup lifecycle hooks of your application as a whole
// This will remove the in memory data store holding onto all of the observers
weakMapElementRegistry.destroyRegistry();

Manage a collection of elements in the browser

Browser Compat

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap

Readme

Keywords

Package Sidebar

Install

npm i weak-map-element-registry

Weekly Downloads

3

Version

0.0.6

License

ISC

Unpacked Size

12.1 kB

Total Files

85

Last publish

Collaborators

  • snewcomer