"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=componentWillUnmount;var _types=require("../util/types");var _binding=_interopRequireDefault(require("../util/binding"));var _symbols=require("../util/symbols");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}const{release,Internals}=_binding.default;/**
 * This is called whenever a component is removed or in the case of a function
 * component is called whenever a component is updated.
 *
 * @param {VTree} vTree - The respecting tree pointing to the component
 */function componentWillUnmount(vTree){const componentTree=_types.ComponentTreeCache.get(vTree);/** @type {VTree[]} */const childTrees=[];_types.ComponentTreeCache.forEach((parentTree,childTree)=>{if(parentTree===componentTree){childTrees.push(childTree)}});const domNode=Internals.NodeCache.get(vTree);// Clean up attached Shadow DOM.
if(domNode&&/** @type {any} */domNode.shadowRoot){release(/** @type {any} */domNode.shadowRoot)}vTree.childNodes.forEach(componentWillUnmount);if(!_types.InstanceCache.has(componentTree)){return}const instance=_types.InstanceCache.get(componentTree);_types.InstanceCache.delete(componentTree);// Empty out all hooks for gc. If using a stateless class or function, they
// may not have this value set.
if(instance[_symbols.$$hooks]){instance[_symbols.$$hooks].fns.length=0;instance[_symbols.$$hooks].i=0}_types.ComponentTreeCache.delete(vTree);// If there is a parent, ensure it is called recursively.
if(_types.ComponentTreeCache.has(componentTree)){componentWillUnmount(componentTree)}// Ensure this is a stateful component. Stateless components do not get
// lifecycle events yet.
instance&&instance.componentWillUnmount&&instance.componentWillUnmount()}module.exports=exports.default;