import type { Fiber } from 'react-reconciler' ; import { addChild } from '../core/addChild' ; import { removeChild } from '../core/removeChild' ; import { getCurrentFiber } from '../fiber/getFiber' ; import { invariant } from '../invariant' ; /**
 * The ParentFiber implement the logic to manage a fiber of a parent component.
 * It provides simple methods for managing reparenting, such as add(), remove() and send().
 */ export class ParentFiber { /** The parent fiber. */ fiber : Fiber | null = null ; /** Find fiber method. */ findFiber ? : ( fiber : Fiber ) => Fiber ; param fiber setFiber ( fiber ) { this . fiber = fiber ; } param findFiber setFinder ( findFiber ? ) { this . findFiber = findFiber ; } returns getCurrent ( ) { invariant ( this . fiber !== null , 'Cannot call ParentFiber methods before it is initialized.' ) ; const current = getCurrentFiber ( this . fiber ) ; return typeof this . findFiber === 'function' ? this . findFiber ( current ) : current ; } param child param position param skipUpdate returns addChild ( child , position , skipUpdate ? ) { return addChild ( this . getCurrent ( ) , child , position , skipUpdate ) ; } param childSelector param skipUpdate returns removeChild ( childSelector , skipUpdate ? ) { return removeChild ( this . getCurrent ( ) , childSelector , skipUpdate ) ; } param toParent param childSelector param position param skipUpdate returns sendChild ( toParent , childSelector , position , skipUpdate ? ) { const child = this . removeChild ( childSelector , skipUpdate ) ; if ( child === null ) { return - 1 ; } return toParent . addChild ( child , position , skipUpdate ) ; } /**
     * Clear the parent fiber.
     */ clear ( ) { this . fiber = null ; } }