Skip to content

Commit

Permalink
Interactivity API: Move init.js to TypeScript (#61723)
Browse files Browse the repository at this point in the history
* Move init.js to typescript

* Throw an error for regions without parent

Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
Co-authored-by: michalczaplinski <czapla@git.wordpress.org>
  • Loading branch information
4 people authored May 16, 2024
1 parent 7d2b5c6 commit cc49981
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { hydrate } from 'preact';
import { hydrate, type ContainerNode, type ComponentChild } from 'preact';
/**
* Internal dependencies
*/
Expand All @@ -11,7 +11,10 @@ import { directivePrefix } from './constants';

// Keep the same root fragment for each interactive region node.
const regionRootFragments = new WeakMap();
export const getRegionRootFragment = ( region ) => {
export const getRegionRootFragment = ( region: Element ): ContainerNode => {
if ( ! region.parentElement ) {
throw Error( 'The passed region should be an element with a parent.' );
}
if ( ! regionRootFragments.has( region ) ) {
regionRootFragments.set(
region,
Expand All @@ -29,7 +32,7 @@ function yieldToMain() {
}

// Initial vDOM regions associated with its DOM element.
export const initialVdom = new WeakMap();
export const initialVdom = new WeakMap< Element, ComponentChild[] >();

// Initialize the router with the initial DOM.
export const init = async () => {
Expand Down

0 comments on commit cc49981

Please sign in to comment.