react-html-element
Advanced tools
Comparing version 4.0.2-fix-react-dom-2376cae.2 to 4.0.2-fix-react-dom-954ceeb.1
@@ -55,2 +55,11 @@ "use strict"; | ||
var react_dom_client_1 = require("./react-dom-client"); | ||
var awaitValue = function (awaiter) { return new Promise(function (resolve) { | ||
var result = awaiter(); | ||
if (result) { | ||
resolve(result); | ||
} | ||
else { | ||
setTimeout(function () { return resolve(awaitValue(awaiter)); }, 100); | ||
} | ||
}); }; | ||
var ReactHTMLElement = /** @class */ (function (_super) { | ||
@@ -62,2 +71,3 @@ __extends(ReactHTMLElement, _super); | ||
var _this = _super.call(this) || this; | ||
_this._awaitingRoot = false; | ||
_this.template = template; | ||
@@ -98,11 +108,20 @@ _this.mountSelector = mountSelector; | ||
var _a; | ||
var _this = this; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!this._awaitingRoot) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, awaitValue(function () { return _this._root; })]; | ||
case 1: | ||
_b.sent(); | ||
_b.label = 2; | ||
case 2: | ||
if (this._root) | ||
return [2 /*return*/, this._root]; | ||
this._awaitingRoot = true; | ||
_a = this; | ||
return [4 /*yield*/, (0, react_dom_client_1.getCreateRoot)()]; | ||
case 1: | ||
case 3: | ||
_a._root = (_b.sent())(this.mountPoint); | ||
this._awaitingRoot = false; | ||
return [2 /*return*/, this._root]; | ||
@@ -109,0 +128,0 @@ } |
@@ -11,2 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { getCreateRoot } from './react-dom-client'; | ||
const awaitValue = (awaiter) => new Promise((resolve) => { | ||
const result = awaiter(); | ||
if (result) { | ||
resolve(result); | ||
} | ||
else { | ||
setTimeout(() => resolve(awaitValue(awaiter)), 100); | ||
} | ||
}); | ||
class ReactHTMLElement extends HTMLElement { | ||
@@ -35,5 +44,10 @@ getShadowRoot() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this._awaitingRoot) { | ||
yield awaitValue(() => this._root); | ||
} | ||
if (this._root) | ||
return this._root; | ||
this._awaitingRoot = true; | ||
this._root = (yield getCreateRoot())(this.mountPoint); | ||
this._awaitingRoot = false; | ||
return this._root; | ||
@@ -61,2 +75,3 @@ }); | ||
super(); | ||
this._awaitingRoot = false; | ||
this.template = template; | ||
@@ -63,0 +78,0 @@ this.mountSelector = mountSelector; |
{ | ||
"name": "react-html-element", | ||
"version": "4.0.2-fix-react-dom-2376cae.2", | ||
"version": "4.0.2-fix-react-dom-954ceeb.1", | ||
"description": "An HTMLElement extension that provides a simple setup for Web Components using React.", | ||
@@ -5,0 +5,0 @@ "main": "module/index.js", |
@@ -9,2 +9,3 @@ import type ReactDOM from 'react-dom'; | ||
private _root?; | ||
private _awaitingRoot; | ||
private getShadowRoot; | ||
@@ -11,0 +12,0 @@ private template; |
28083
415