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
- element: DOM Node to observe
- 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