"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "InitializationErrorThrower", {
    enumerable: true,
    get: function() {
        return InitializationErrorThrower;
    }
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _initializationErrorState = require("./initializationErrorState");
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const InitializationErrorThrower = ()=>{
    const [error, setError] = (0, _react.useState)(null);
    (0, _react.useEffect)(()=>{
        // 检查初始错误
        const currentError = _initializationErrorState.initializationErrorState.getError();
        if (currentError) {
            setError(currentError);
            return;
        }
        // 订阅错误变化
        const unsubscribe = _initializationErrorState.initializationErrorState.subscribe(()=>{
            const newError = _initializationErrorState.initializationErrorState.getError();
            setError(newError);
        });
        return unsubscribe;
    }, []);
    // 如果有错误，抛出错误给 ErrorBoundary
    if (error) {
        throw error;
    }
    return null;
};

//# sourceMappingURL=InitializationErrorThrower.js.map