UNPKG

1.29 kBTypeScriptView Raw
1import { NodePart } from "lit-html";
2/** #################################################################################
3 ** The purpose of this module is to provide an API to clean up the node parts cache.
4 ** This is to avoid memory leaks from parts being added and removed to the template.
5 ** This is necessary since lit-html currently do not provide a way of cleaning up after a directive.
6 ** In the ideal world we would be able to cache the parts in a weakmap, however that makes
7 ** us unable to loop over the map which is required for updating the translations when the lang changes.
8 ** This module will be obsolete the day lit-html provides a way of cleaning up after a directive
9 ** ##################################################################################
10
11/**
12 * Check whether the part is still connected / has been removed from the DOM.
13 * @param part
14 */
15export declare function isConnected(part: NodePart): boolean;
16/**
17 * Removes the disconnected parts from the cache.
18 */
19export declare function removeDisconnectedParts(map: Map<NodePart, unknown>): void;
20/**
21 * Starts an interval that cleans up the part cache map each X ms.
22 * @param map
23 * @param ms
24 */
25export declare function attachPartsGarbageCollector(map: Map<NodePart, unknown>, ms: number): void;