static-injector
Version:
Angular 依赖注入独立版本;Angular dependency injection standalone version
1,743 lines (1,695 loc) • 64.2 kB
JavaScript
// src/import/di/interface/provider.ts
function isEnvironmentProviders(value) {
return value && !!value.ɵproviders;
}
// src/import/errors.ts
var RuntimeError = class extends Error {
constructor(code, message) {
super(formatRuntimeError(code, message));
this.code = code;
}
};
function formatRuntimeError(code, message) {
const fullCode = `NG0${Math.abs(code)}`;
const errorMessage = `${fullCode}${message ? ": " + message : ""}`;
if (false) {
}
return errorMessage;
}
// src/import/render3/definition_factory.ts
function getFactoryDef(type, throwNotFound) {
return () => new type();
}
// src/import/util/property.ts
function getClosureSafeProperty(objWithPropertyToExtract) {
for (const key in objWithPropertyToExtract) {
if (objWithPropertyToExtract[key] === getClosureSafeProperty) {
return key;
}
}
throw Error("Could not find renamed property on target object.");
}
// src/import/render3/fields.ts
var NG_FACTORY_DEF = getClosureSafeProperty({
ɵfac: getClosureSafeProperty
});
var NG_ENV_ID = getClosureSafeProperty({
__NG_ENV_ID__: getClosureSafeProperty
});
// src/import/util/empty.ts
var EMPTY_ARRAY = [];
if (false) {
}
// src/import/util/stringify.ts
function stringify(token) {
if (typeof token === "string") {
return token;
}
if (Array.isArray(token)) {
return `[${token.map(stringify).join(", ")}]`;
}
if (token == null) {
return "" + token;
}
const name = token.overriddenName || token.name;
if (name) {
return `${name}`;
}
const result = token.toString();
if (result == null) {
return "" + result;
}
const newLineIndex = result.indexOf("\n");
return newLineIndex >= 0 ? result.slice(0, newLineIndex) : result;
}
// src/import/di/forward_ref.ts
var __forward_ref__ = getClosureSafeProperty({
__forward_ref__: getClosureSafeProperty
});
function forwardRef(forwardRefFn) {
forwardRefFn.__forward_ref__ = forwardRef;
forwardRefFn.toString = function() {
return stringify(this());
};
return forwardRefFn;
}
function resolveForwardRef(type) {
return isForwardRef(type) ? type() : type;
}
function isForwardRef(fn) {
return typeof fn === "function" && fn.hasOwnProperty(__forward_ref__) && fn.__forward_ref__ === forwardRef;
}
// src/import/di/interface/defs.ts
function ɵɵdefineInjectable(opts) {
return {
token: opts.token,
providedIn: opts.providedIn || null,
factory: opts.factory,
value: void 0
};
}
function ɵɵdefineInjector(options) {
return { providers: options.providers || [], imports: options.imports || [] };
}
function getInjectableDef(type) {
return getOwnDefinition(type, NG_PROV_DEF) || {
token: type,
factory: () => new type(),
...type.injectOptions
};
}
function isInjectable(type) {
return getInjectableDef(type) !== null;
}
function getOwnDefinition(type, field) {
return type.hasOwnProperty(field) ? type[field] : null;
}
function getInheritedInjectableDef(type) {
const def = type && (type[NG_PROV_DEF] || null);
if (def) {
return def;
} else {
return null;
}
}
function getInjectorDef(type) {
return type && (type.hasOwnProperty(NG_INJ_DEF) || false) ? type[NG_INJ_DEF] : null;
}
var NG_PROV_DEF = getClosureSafeProperty({
ɵprov: getClosureSafeProperty
});
var NG_INJ_DEF = getClosureSafeProperty({
ɵinj: getClosureSafeProperty
});
// src/import/di/injection_token.ts
var InjectionToken = class {
/**
* @param _desc Description for the token,
* used only for debugging purposes,
* it should but does not need to be unique
* @param options Options for the token's usage, as described above
*/
constructor(_desc, options) {
this._desc = _desc;
this.ɵprov = void 0;
if (typeof options === "number") {
} else if (options !== void 0) {
this.ɵprov = ɵɵdefineInjectable({
token: this,
providedIn: options.providedIn || "root",
factory: options.factory
});
}
}
/** @internal */
ngMetadataName = "InjectionToken";
ɵprov;
/**
* @internal
*/
get multi() {
return this;
}
toString() {
return `InjectionToken ${this._desc}`;
}
};
// src/import/di/initializer_token.ts
var ENVIRONMENT_INITIALIZER = new InjectionToken("");
// src/import/render3/errors_di.ts
function throwProviderNotFoundError(token, injectorName) {
const errorMessage = null;
throw new RuntimeError(-201 /* PROVIDER_NOT_FOUND */, errorMessage);
}
// src/import/di/interface/injector.ts
var DecoratorFlags = /* @__PURE__ */ ((DecoratorFlags2) => {
DecoratorFlags2[DecoratorFlags2["Inject"] = -1] = "Inject";
return DecoratorFlags2;
})(DecoratorFlags || {});
var InjectFlags = /* @__PURE__ */ ((InjectFlags2) => {
InjectFlags2[InjectFlags2["Default"] = 0] = "Default";
InjectFlags2[InjectFlags2["Self"] = 2] = "Self";
InjectFlags2[InjectFlags2["SkipSelf"] = 4] = "SkipSelf";
InjectFlags2[InjectFlags2["Optional"] = 8] = "Optional";
return InjectFlags2;
})(InjectFlags || {});
var InternalInjectFlags = /* @__PURE__ */ ((InternalInjectFlags2) => {
InternalInjectFlags2[InternalInjectFlags2["Default"] = 0] = "Default";
InternalInjectFlags2[InternalInjectFlags2["Self"] = 2] = "Self";
InternalInjectFlags2[InternalInjectFlags2["SkipSelf"] = 4] = "SkipSelf";
InternalInjectFlags2[InternalInjectFlags2["Optional"] = 8] = "Optional";
return InternalInjectFlags2;
})(InternalInjectFlags || {});
// src/import/di/inject_switch.ts
var _injectImplementation;
function getInjectImplementation() {
return _injectImplementation;
}
function setInjectImplementation(impl) {
const previous = _injectImplementation;
_injectImplementation = impl;
return previous;
}
function injectRootLimpMode(token, notFoundValue, flags) {
const injectableDef = getInjectableDef(token);
if (injectableDef && injectableDef.providedIn == "root") {
return injectableDef.value === void 0 ? injectableDef.value = injectableDef.factory() : injectableDef.value;
}
if (flags & 8 /* Optional */) return null;
if (notFoundValue !== void 0) return notFoundValue;
throwProviderNotFoundError(token, "Injector");
}
// src/import/di/injector_compatibility.ts
var _THROW_IF_NOT_FOUND = {};
var THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
var DI_DECORATOR_FLAG = "__NG_DI_FLAG__";
var NG_TEMP_TOKEN_PATH = "ngTempTokenPath";
var NG_TOKEN_PATH = "ngTokenPath";
var NEW_LINE = /\n/gm;
var NO_NEW_LINE = "ɵ";
var SOURCE = "__source";
var _currentInjector = void 0;
function getCurrentInjector() {
return _currentInjector;
}
function setCurrentInjector(injector) {
const former = _currentInjector;
_currentInjector = injector;
return former;
}
function injectInjectorOnly(token, flags = 0 /* Default */) {
if (_currentInjector === void 0) {
throw new RuntimeError(-203 /* MISSING_INJECTION_CONTEXT */, null);
} else if (_currentInjector === null) {
return injectRootLimpMode(token, void 0, flags);
} else {
const value = _currentInjector.get(
token,
flags & 8 /* Optional */ ? null : void 0,
flags
);
return value;
}
}
function ɵɵinject(token, flags = 0 /* Default */) {
return (getInjectImplementation() || injectInjectorOnly)(
resolveForwardRef(token),
flags
);
}
function ɵɵinvalidFactoryDep(index) {
throw new RuntimeError(202 /* INVALID_FACTORY_DEPENDENCY */, null);
}
function inject(token, flags = 0 /* Default */) {
return ɵɵinject(token, convertToBitFlags(flags));
}
function convertToBitFlags(flags) {
if (typeof flags === "undefined" || typeof flags === "number") {
return flags;
}
return 0 /* Default */ | // comment to force a line break in the formatter
(flags.optional && 8 /* Optional */) | 0 | (flags.self && 2 /* Self */) | (flags.skipSelf && 4 /* SkipSelf */);
}
function injectArgs(types) {
const args = [];
for (let i = 0; i < types.length; i++) {
const arg = resolveForwardRef(types[i]);
if (Array.isArray(arg)) {
if (arg.length === 0) {
throw new RuntimeError(900 /* INVALID_DIFFER_INPUT */, null);
}
let type = void 0;
let flags = 0 /* Default */;
for (let j = 0; j < arg.length; j++) {
const meta = arg[j];
const flag = getInjectFlag(meta);
if (typeof flag === "number") {
if (flag === -1 /* Inject */) {
type = meta.token;
} else {
flags |= flag;
}
} else {
type = meta;
}
}
args.push(ɵɵinject(type, flags));
} else {
args.push(ɵɵinject(arg));
}
}
return args;
}
function attachInjectFlag(decorator, flag) {
decorator[DI_DECORATOR_FLAG] = flag;
decorator.prototype[DI_DECORATOR_FLAG] = flag;
return decorator;
}
function getInjectFlag(token) {
return token[DI_DECORATOR_FLAG];
}
function catchInjectorError(e, token, injectorErrorName, source) {
const tokenPath = e[NG_TEMP_TOKEN_PATH];
if (token[SOURCE]) {
tokenPath.unshift(token[SOURCE]);
}
e.message = formatError(
"\n" + e.message,
tokenPath,
injectorErrorName,
source
);
e[NG_TOKEN_PATH] = tokenPath;
e[NG_TEMP_TOKEN_PATH] = null;
throw e;
}
function formatError(text, obj, injectorErrorName, source = null) {
text = text && text.charAt(0) === "\n" && text.charAt(1) == NO_NEW_LINE ? text.slice(2) : text;
let context = stringify(obj);
if (Array.isArray(obj)) {
context = obj.map(stringify).join(" -> ");
} else if (typeof obj === "object") {
const parts = [];
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
const value = obj[key];
parts.push(
key + ":" + (typeof value === "string" ? JSON.stringify(value) : stringify(value))
);
}
}
context = `{${parts.join(", ")}}`;
}
return `${injectorErrorName}${source ? "(" + source + ")" : ""}[${context}]: ${text.replace(
NEW_LINE,
"\n "
)}`;
}
// src/import/di/injector_token.ts
var INJECTOR = new InjectionToken(
"",
// Disable tslint because this is const enum which gets inlined not top level prop access.
// tslint:disable-next-line: no-toplevel-property-access
-1 /* Injector */
// Special value used by Ivy to identify `Injector`.
);
// src/import/di/internal_tokens.ts
var INJECTOR_DEF_TYPES = new InjectionToken("");
// src/import/di/null_injector.ts
var NullInjector = class {
get(token, notFoundValue = THROW_IF_NOT_FOUND) {
if (notFoundValue === THROW_IF_NOT_FOUND) {
const error = new Error(
`NullInjectorError: No provider for ${stringify(token)}!`
);
error.name = "NullInjectorError";
throw error;
}
return notFoundValue;
}
};
// src/import/di/provider_collection.ts
function importProvidersFrom(...sources) {
return {
ɵproviders: internalImportProvidersFrom(true, sources),
ɵfromNgModule: true
};
}
function internalImportProvidersFrom(checkForStandaloneCmp, ...sources) {
const providersOut = [];
const dedup = /* @__PURE__ */ new Set();
let injectorTypesWithProviders;
const collectProviders = (provider) => {
providersOut.push(provider);
};
if (injectorTypesWithProviders !== void 0) {
processInjectorTypesWithProviders(
injectorTypesWithProviders,
collectProviders
);
}
return providersOut;
}
function processInjectorTypesWithProviders(typesWithProviders, visitor) {
for (let i = 0; i < typesWithProviders.length; i++) {
const { ngModule, providers } = typesWithProviders[i];
}
}
var USE_VALUE = getClosureSafeProperty({
provide: String,
useValue: getClosureSafeProperty
});
function isValueProvider(value) {
return value !== null && typeof value === "object" && USE_VALUE in value;
}
function isExistingProvider(value) {
return !!(value && value.useExisting);
}
function isFactoryProvider(value) {
return !!(value && value.useFactory);
}
function isTypeProvider(value) {
return typeof value === "function";
}
// src/import/di/scope.ts
var INJECTOR_SCOPE = new InjectionToken("");
// src/import/di/r3_injector.ts
var NOT_YET = {};
var CIRCULAR = {};
var NULL_INJECTOR = void 0;
function getNullInjector() {
if (NULL_INJECTOR === void 0) {
NULL_INJECTOR = new NullInjector();
}
return NULL_INJECTOR;
}
var EnvironmentInjector = class {
};
var R3Injector = class extends EnvironmentInjector {
constructor(providers, parent, source, scopes) {
super();
this.parent = parent;
this.source = source;
this.scopes = scopes;
forEachSingleProvider(
providers,
(provider) => this.processProvider(provider)
);
this.records.set(INJECTOR, makeRecord(void 0, this));
if (scopes.has("environment")) {
this.records.set(EnvironmentInjector, makeRecord(void 0, this));
}
const record = this.records.get(
INJECTOR_SCOPE
);
if (record != null && typeof record.value === "string") {
this.scopes.add(record.value);
}
this.injectorDefTypes = new Set(
this.get(INJECTOR_DEF_TYPES, EMPTY_ARRAY, 2 /* Self */)
);
}
/**
* Map of tokens to records which contain the instances of those tokens.
* - `null` value implies that we don't have the record. Used by tree-shakable injectors
* to prevent further searches.
*/
records = /* @__PURE__ */ new Map();
/**
* Set of values instantiated by this injector which contain `ngOnDestroy` lifecycle hooks.
*/
_ngOnDestroyHooks = /* @__PURE__ */ new Set();
_onDestroyHooks = [];
/**
* Flag indicating that this injector was previously destroyed.
*/
get destroyed() {
return this._destroyed;
}
_destroyed = false;
injectorDefTypes;
/**
* Destroy the injector and release references to every instance or provider associated with it.
*
* Also calls the `OnDestroy` lifecycle hooks of every instance that was created for which a
* hook was found.
*/
destroy() {
assertNotDestroyed(this);
this._destroyed = true;
try {
for (const service of this._ngOnDestroyHooks) {
service.ngOnDestroy();
}
const onDestroyHooks = this._onDestroyHooks;
this._onDestroyHooks = [];
for (const hook of onDestroyHooks) {
hook();
}
} finally {
this.records.clear();
this._ngOnDestroyHooks.clear();
this.injectorDefTypes.clear();
}
}
onDestroy(callback) {
assertNotDestroyed(this);
this._onDestroyHooks.push(callback);
return () => this.removeOnDestroy(callback);
}
runInContext(fn) {
assertNotDestroyed(this);
const previousInjector = setCurrentInjector(this);
const previousInjectImplementation = setInjectImplementation(void 0);
if (false) {
}
try {
return fn();
} finally {
setCurrentInjector(previousInjector);
setInjectImplementation(previousInjectImplementation);
}
}
get(token, notFoundValue = THROW_IF_NOT_FOUND, flags = 0 /* Default */) {
assertNotDestroyed(this);
if (token.hasOwnProperty(NG_ENV_ID)) {
return token[NG_ENV_ID](this);
}
flags = convertToBitFlags(flags);
if (false) {
}
const previousInjector = setCurrentInjector(this);
const previousInjectImplementation = setInjectImplementation(void 0);
try {
if (!(flags & 4 /* SkipSelf */)) {
let record = this.records.get(token);
if (record === void 0) {
const def = couldBeInjectableType(token) && getInjectableDef(token);
if (def && this.injectableDefInScope(def)) {
if (false) {
}
record = makeRecord(
injectableDefOrInjectorDefFactory(token),
NOT_YET
);
} else {
record = null;
}
this.records.set(token, record);
}
if (record != null) {
return this.hydrate(token, record);
}
}
const nextInjector = !(flags & 2 /* Self */) ? this.parent : getNullInjector();
notFoundValue = flags & 8 /* Optional */ && notFoundValue === THROW_IF_NOT_FOUND ? null : notFoundValue;
return nextInjector.get(token, notFoundValue);
} catch (e) {
if (e.name === "NullInjectorError") {
const path = e[NG_TEMP_TOKEN_PATH] = e[NG_TEMP_TOKEN_PATH] || [];
path.unshift(stringify(token));
if (previousInjector) {
throw e;
} else {
return catchInjectorError(e, token, "R3InjectorError", this.source);
}
} else {
throw e;
}
} finally {
setInjectImplementation(previousInjectImplementation);
setCurrentInjector(previousInjector);
}
}
/** @internal */
resolveInjectorInitializers() {
const previousInjector = setCurrentInjector(this);
const previousInjectImplementation = setInjectImplementation(void 0);
if (false) {
}
try {
const initializers = this.get(
ENVIRONMENT_INITIALIZER,
EMPTY_ARRAY,
2 /* Self */
);
if (false) {
}
for (const initializer of initializers) {
initializer();
}
} finally {
setCurrentInjector(previousInjector);
setInjectImplementation(previousInjectImplementation);
}
}
toString() {
const tokens = [];
const records = this.records;
for (const token of records.keys()) {
tokens.push(stringify(token));
}
return `R3Injector[${tokens.join(", ")}]`;
}
/**
* Process a `SingleProvider` and add it.
*/
processProvider(provider) {
provider = resolveForwardRef(provider);
let token = isTypeProvider(provider) ? provider : resolveForwardRef(provider && provider.provide);
const record = providerToRecord(provider);
if (false) {
}
if (!isTypeProvider(provider) && provider.multi === true) {
let multiRecord = this.records.get(token);
if (multiRecord) {
if (false) {
}
} else {
multiRecord = makeRecord(void 0, NOT_YET, true);
multiRecord.factory = () => injectArgs(multiRecord.multi);
this.records.set(token, multiRecord);
}
token = provider;
multiRecord.multi.push(provider);
} else {
if (false) {
}
}
this.records.set(token, record);
}
hydrate(token, record) {
try {
if (false) {
} else if (record.value === NOT_YET) {
record.value = CIRCULAR;
if (false) {
} else {
record.value = record.factory();
}
}
if (typeof record.value === "object" && record.value && hasOnDestroy(record.value)) {
this._ngOnDestroyHooks.add(record.value);
}
return record.value;
} finally {
}
}
injectableDefInScope(def) {
if (!def.providedIn) {
return false;
}
const providedIn = resolveForwardRef(def.providedIn);
if (typeof providedIn === "string") {
return providedIn === "any" || this.scopes.has(providedIn);
} else {
return this.injectorDefTypes.has(providedIn);
}
}
removeOnDestroy(callback) {
const destroyCBIdx = this._onDestroyHooks.indexOf(callback);
if (destroyCBIdx !== -1) {
this._onDestroyHooks.splice(destroyCBIdx, 1);
}
}
};
function injectableDefOrInjectorDefFactory(token) {
const injectableDef = getInjectableDef(token);
const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
if (factory !== null) {
return factory;
}
if (token instanceof InjectionToken) {
throw new RuntimeError(204 /* INVALID_INJECTION_TOKEN */, null);
}
if (token instanceof Function) {
return getUndecoratedInjectableFactory(token);
}
throw new RuntimeError(204 /* INVALID_INJECTION_TOKEN */, null);
}
function getUndecoratedInjectableFactory(token) {
const paramLength = token.length;
if (paramLength > 0) {
throw new RuntimeError(204 /* INVALID_INJECTION_TOKEN */, null);
}
const inheritedInjectableDef = getInheritedInjectableDef(token);
if (inheritedInjectableDef !== null) {
return () => inheritedInjectableDef.factory(token);
} else {
return () => new token();
}
}
function providerToRecord(provider) {
if (isValueProvider(provider)) {
return makeRecord(void 0, provider.useValue);
} else {
const factory = providerToFactory(provider);
return makeRecord(factory, NOT_YET);
}
}
function providerToFactory(provider, ngModuleType, providers) {
let factory = void 0;
if (false) {
}
if (isTypeProvider(provider)) {
const unwrappedProvider = resolveForwardRef(provider);
return getFactoryDef(unwrappedProvider) || injectableDefOrInjectorDefFactory(unwrappedProvider);
} else {
if (isValueProvider(provider)) {
factory = () => resolveForwardRef(provider.useValue);
} else if (isFactoryProvider(provider)) {
factory = () => provider.useFactory(...injectArgs(provider.deps || []));
} else if (isExistingProvider(provider)) {
factory = () => ɵɵinject(resolveForwardRef(provider.useExisting));
} else {
const classRef = resolveForwardRef(
provider && (provider.useClass || provider.provide)
);
if (false) {
}
if (hasDeps(provider)) {
factory = () => new classRef(...injectArgs(provider.deps));
} else {
return getFactoryDef(classRef) || injectableDefOrInjectorDefFactory(classRef);
}
}
}
return factory;
}
function assertNotDestroyed(injector) {
if (injector.destroyed) {
throw new RuntimeError(205 /* INJECTOR_ALREADY_DESTROYED */, null);
}
}
function makeRecord(factory, value, multi = false) {
return {
factory,
value,
multi: multi ? [] : void 0
};
}
function hasDeps(value) {
return !!value.deps;
}
function hasOnDestroy(value) {
return value !== null && typeof value === "object" && typeof value.ngOnDestroy === "function";
}
function couldBeInjectableType(value) {
return typeof value === "function" || typeof value === "object" && value instanceof InjectionToken;
}
function forEachSingleProvider(providers, fn) {
for (const provider of providers) {
if (Array.isArray(provider)) {
forEachSingleProvider(provider, fn);
} else if (provider && isEnvironmentProviders(provider)) {
forEachSingleProvider(provider.ɵproviders, fn);
} else {
fn(provider);
}
}
}
// src/import/util/closure.ts
function noSideEffects(fn) {
return { toString: fn }.toString();
}
// src/import/util/decorators.ts
function makeMetadataCtor(props) {
return function ctor(...args) {
if (props) {
const values = props(...args);
for (const propName in values) {
this[propName] = values[propName];
}
}
};
}
function makeParamDecorator(name, props, parentClass) {
return noSideEffects(() => {
const metaCtor = makeMetadataCtor(props);
function ParamDecoratorFactory(...args) {
metaCtor.apply(this, args);
return this;
}
if (parentClass) {
}
return ParamDecoratorFactory;
});
}
// src/import/di/metadata.ts
var Inject = attachInjectFlag(
// Disable tslint because `DecoratorFlags` is a const enum which gets inlined.
makeParamDecorator("Inject", (token) => ({ token })),
// tslint:disable-next-line: no-toplevel-property-access
-1 /* Inject */
);
var Optional = (
// Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
// tslint:disable-next-line: no-toplevel-property-access
attachInjectFlag(
makeParamDecorator("Optional"),
8 /* Optional */
)
);
var Self = (
// Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
// tslint:disable-next-line: no-toplevel-property-access
attachInjectFlag(makeParamDecorator("Self"), 2 /* Self */)
);
var SkipSelf = (
// Disable tslint because `InternalInjectFlags` is a const enum which gets inlined.
// tslint:disable-next-line: no-toplevel-property-access
attachInjectFlag(
makeParamDecorator("SkipSelf"),
4 /* SkipSelf */
)
);
// src/import/di/create_injector.ts
function createInjector(defType, parent = null, additionalProviders = null, name) {
const injector = createInjectorWithoutInjectorInstances(
defType,
parent,
additionalProviders,
name
);
injector.resolveInjectorInitializers();
return injector;
}
function createInjectorWithoutInjectorInstances(defType, parent = null, additionalProviders = null, name, scopes = /* @__PURE__ */ new Set()) {
const providers = [
additionalProviders || EMPTY_ARRAY,
importProvidersFrom(defType)
];
name = name || (typeof defType === "object" ? void 0 : stringify(defType));
return new R3Injector(
providers,
parent || getNullInjector(),
name || null,
scopes
);
}
// src/import/di/injector.ts
var Injector = class _Injector {
static THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
static NULL = /* @__PURE__ */ new NullInjector();
static create(options, parent) {
if (Array.isArray(options)) {
return createInjector({ name: "" }, parent, options, "");
} else {
const name = options.name ?? "";
return createInjector({ name }, options.parent, options.providers, name);
}
}
/** @nocollapse */
static ɵprov = (
/** @pureOrBreakMyCode */
/* @__PURE__ */ ɵɵdefineInjectable({
token: _Injector,
providedIn: "any",
factory: () => ɵɵinject(INJECTOR)
})
);
/**
* @internal
* @nocollapse
*/
static __NG_ELEMENT_ID__ = -1 /* Injector */;
};
// src/import/render3/instructions/di.ts
function ɵɵinvalidFactory() {
const msg = "invalid";
throw new Error(msg);
}
// src/primitives/signals/src/equality.ts
function defaultEquals(a, b) {
return Object.is(a, b);
}
// src/primitives/signals/src/graph.ts
var activeConsumer = null;
var inNotificationPhase = false;
var epoch = 1;
var SIGNAL = /* @__PURE__ */ Symbol("SIGNAL");
function setActiveConsumer(consumer) {
const prev = activeConsumer;
activeConsumer = consumer;
return prev;
}
function getActiveConsumer() {
return activeConsumer;
}
function isInNotificationPhase() {
return inNotificationPhase;
}
var REACTIVE_NODE = {
version: 0,
lastCleanEpoch: 0,
dirty: false,
producerNode: void 0,
producerLastReadVersion: void 0,
producerIndexOfThis: void 0,
nextProducerIndex: 0,
liveConsumerNode: void 0,
liveConsumerIndexOfThis: void 0,
consumerAllowSignalWrites: false,
consumerIsAlwaysLive: false,
kind: "unknown",
producerMustRecompute: () => false,
producerRecomputeValue: () => {
},
consumerMarkedDirty: () => {
},
consumerOnSignalRead: () => {
}
};
function producerAccessed(node) {
if (inNotificationPhase) {
throw new Error(
false ? `Assertion error: signal read during notification phase` : ""
);
}
if (activeConsumer === null) {
return;
}
activeConsumer.consumerOnSignalRead(node);
const idx = activeConsumer.nextProducerIndex++;
assertConsumerNode(activeConsumer);
if (idx < activeConsumer.producerNode.length && activeConsumer.producerNode[idx] !== node) {
if (consumerIsLive(activeConsumer)) {
const staleProducer = activeConsumer.producerNode[idx];
producerRemoveLiveConsumerAtIndex(
staleProducer,
activeConsumer.producerIndexOfThis[idx]
);
}
}
if (activeConsumer.producerNode[idx] !== node) {
activeConsumer.producerNode[idx] = node;
activeConsumer.producerIndexOfThis[idx] = consumerIsLive(activeConsumer) ? producerAddLiveConsumer(node, activeConsumer, idx) : 0;
}
activeConsumer.producerLastReadVersion[idx] = node.version;
}
function producerIncrementEpoch() {
epoch++;
}
function producerUpdateValueVersion(node) {
if (consumerIsLive(node) && !node.dirty) {
return;
}
if (!node.dirty && node.lastCleanEpoch === epoch) {
return;
}
if (!node.producerMustRecompute(node) && !consumerPollProducersForChange(node)) {
producerMarkClean(node);
return;
}
node.producerRecomputeValue(node);
producerMarkClean(node);
}
function producerNotifyConsumers(node) {
if (node.liveConsumerNode === void 0) {
return;
}
const prev = inNotificationPhase;
inNotificationPhase = true;
try {
for (const consumer of node.liveConsumerNode) {
if (!consumer.dirty) {
consumerMarkDirty(consumer);
}
}
} finally {
inNotificationPhase = prev;
}
}
function producerUpdatesAllowed() {
return activeConsumer?.consumerAllowSignalWrites !== false;
}
function consumerMarkDirty(node) {
node.dirty = true;
producerNotifyConsumers(node);
node.consumerMarkedDirty?.(node);
}
function producerMarkClean(node) {
node.dirty = false;
node.lastCleanEpoch = epoch;
}
function consumerBeforeComputation(node) {
node && (node.nextProducerIndex = 0);
return setActiveConsumer(node);
}
function consumerAfterComputation(node, prevConsumer) {
setActiveConsumer(prevConsumer);
if (!node || node.producerNode === void 0 || node.producerIndexOfThis === void 0 || node.producerLastReadVersion === void 0) {
return;
}
if (consumerIsLive(node)) {
for (let i = node.nextProducerIndex; i < node.producerNode.length; i++) {
producerRemoveLiveConsumerAtIndex(
node.producerNode[i],
node.producerIndexOfThis[i]
);
}
}
while (node.producerNode.length > node.nextProducerIndex) {
node.producerNode.pop();
node.producerLastReadVersion.pop();
node.producerIndexOfThis.pop();
}
}
function consumerPollProducersForChange(node) {
assertConsumerNode(node);
for (let i = 0; i < node.producerNode.length; i++) {
const producer = node.producerNode[i];
const seenVersion = node.producerLastReadVersion[i];
if (seenVersion !== producer.version) {
return true;
}
producerUpdateValueVersion(producer);
if (seenVersion !== producer.version) {
return true;
}
}
return false;
}
function consumerDestroy(node) {
assertConsumerNode(node);
if (consumerIsLive(node)) {
for (let i = 0; i < node.producerNode.length; i++) {
producerRemoveLiveConsumerAtIndex(
node.producerNode[i],
node.producerIndexOfThis[i]
);
}
}
node.producerNode.length = node.producerLastReadVersion.length = node.producerIndexOfThis.length = 0;
if (node.liveConsumerNode) {
node.liveConsumerNode.length = node.liveConsumerIndexOfThis.length = 0;
}
}
function producerAddLiveConsumer(node, consumer, indexOfThis) {
assertProducerNode(node);
if (node.liveConsumerNode.length === 0 && isConsumerNode(node)) {
for (let i = 0; i < node.producerNode.length; i++) {
node.producerIndexOfThis[i] = producerAddLiveConsumer(
node.producerNode[i],
node,
i
);
}
}
node.liveConsumerIndexOfThis.push(indexOfThis);
return node.liveConsumerNode.push(consumer) - 1;
}
function producerRemoveLiveConsumerAtIndex(node, idx) {
assertProducerNode(node);
if (false) {
throw new Error(
`Assertion error: active consumer index ${idx} is out of bounds of ${node.liveConsumerNode.length} consumers)`
);
}
if (node.liveConsumerNode.length === 1 && isConsumerNode(node)) {
for (let i = 0; i < node.producerNode.length; i++) {
producerRemoveLiveConsumerAtIndex(
node.producerNode[i],
node.producerIndexOfThis[i]
);
}
}
const lastIdx = node.liveConsumerNode.length - 1;
node.liveConsumerNode[idx] = node.liveConsumerNode[lastIdx];
node.liveConsumerIndexOfThis[idx] = node.liveConsumerIndexOfThis[lastIdx];
node.liveConsumerNode.length--;
node.liveConsumerIndexOfThis.length--;
if (idx < node.liveConsumerNode.length) {
const idxProducer = node.liveConsumerIndexOfThis[idx];
const consumer = node.liveConsumerNode[idx];
assertConsumerNode(consumer);
consumer.producerIndexOfThis[idxProducer] = idx;
}
}
function consumerIsLive(node) {
return node.consumerIsAlwaysLive || (node?.liveConsumerNode?.length ?? 0) > 0;
}
function assertConsumerNode(node) {
node.producerNode ??= [];
node.producerIndexOfThis ??= [];
node.producerLastReadVersion ??= [];
}
function assertProducerNode(node) {
node.liveConsumerNode ??= [];
node.liveConsumerIndexOfThis ??= [];
}
function isConsumerNode(node) {
return node.producerNode !== void 0;
}
// src/primitives/signals/src/computed.ts
function createComputed(computation) {
const node = Object.create(COMPUTED_NODE);
node.computation = computation;
const computed2 = () => {
producerUpdateValueVersion(node);
producerAccessed(node);
if (node.value === ERRORED) {
throw node.error;
}
return node.value;
};
computed2[SIGNAL] = node;
return computed2;
}
var UNSET = /* @__PURE__ */ Symbol("UNSET");
var COMPUTING = /* @__PURE__ */ Symbol("COMPUTING");
var ERRORED = /* @__PURE__ */ Symbol("ERRORED");
var COMPUTED_NODE = /* @__PURE__ */ (() => ({
...REACTIVE_NODE,
value: UNSET,
dirty: true,
error: null,
equal: defaultEquals,
kind: "computed",
producerMustRecompute(node) {
return node.value === UNSET || node.value === COMPUTING;
},
producerRecomputeValue(node) {
if (node.value === COMPUTING) {
throw new Error("Detected cycle in computations.");
}
const oldValue = node.value;
node.value = COMPUTING;
const prevConsumer = consumerBeforeComputation(node);
let newValue;
let wasEqual = false;
try {
newValue = node.computation();
setActiveConsumer(null);
wasEqual = oldValue !== UNSET && oldValue !== ERRORED && newValue !== ERRORED && node.equal(oldValue, newValue);
} catch (err) {
newValue = ERRORED;
node.error = err;
} finally {
consumerAfterComputation(node, prevConsumer);
}
if (wasEqual) {
node.value = oldValue;
return;
}
node.value = newValue;
node.version++;
}
}))();
// src/primitives/signals/src/errors.ts
function defaultThrowError() {
throw new Error();
}
var throwInvalidWriteToSignalErrorFn = defaultThrowError;
function throwInvalidWriteToSignalError(node) {
throwInvalidWriteToSignalErrorFn(node);
}
// src/primitives/signals/src/signal.ts
var postSignalSetFn = null;
function createSignal(initialValue) {
const node = Object.create(SIGNAL_NODE);
node.value = initialValue;
const getter = () => {
producerAccessed(node);
return node.value;
};
getter[SIGNAL] = node;
return getter;
}
function signalSetFn(node, newValue) {
if (!producerUpdatesAllowed()) {
throwInvalidWriteToSignalError(node);
}
if (!node.equal(node.value, newValue)) {
node.value = newValue;
signalValueChanged(node);
}
}
function signalUpdateFn(node, updater) {
if (!producerUpdatesAllowed()) {
throwInvalidWriteToSignalError(node);
}
signalSetFn(node, updater(node.value));
}
var SIGNAL_NODE = /* @__PURE__ */ (() => ({
...REACTIVE_NODE,
equal: defaultEquals,
value: void 0,
kind: "signal"
}))();
function signalValueChanged(node) {
node.version++;
producerIncrementEpoch();
producerNotifyConsumers(node);
postSignalSetFn?.();
}
// src/primitives/signals/src/linked_signal.ts
function createLinkedSignal(sourceFn, computationFn, equalityFn) {
const node = Object.create(LINKED_SIGNAL_NODE);
node.source = sourceFn;
node.computation = computationFn;
if (equalityFn != void 0) {
node.equal = equalityFn;
}
const linkedSignalGetter = () => {
producerUpdateValueVersion(node);
producerAccessed(node);
if (node.value === ERRORED) {
throw node.error;
}
return node.value;
};
const getter = linkedSignalGetter;
getter[SIGNAL] = node;
return getter;
}
function linkedSignalSetFn(node, newValue) {
producerUpdateValueVersion(node);
signalSetFn(node, newValue);
producerMarkClean(node);
}
function linkedSignalUpdateFn(node, updater) {
producerUpdateValueVersion(node);
signalUpdateFn(node, updater);
producerMarkClean(node);
}
var LINKED_SIGNAL_NODE = /* @__PURE__ */ (() => ({
...REACTIVE_NODE,
value: UNSET,
dirty: true,
error: null,
equal: defaultEquals,
producerMustRecompute(node) {
return node.value === UNSET || node.value === COMPUTING;
},
producerRecomputeValue(node) {
if (node.value === COMPUTING) {
throw new Error("Detected cycle in computations.");
}
const oldValue = node.value;
node.value = COMPUTING;
const prevConsumer = consumerBeforeComputation(node);
let newValue;
try {
const newSourceValue = node.source();
const prev = oldValue === UNSET || oldValue === ERRORED ? void 0 : {
source: node.sourceValue,
value: oldValue
};
newValue = node.computation(newSourceValue, prev);
node.sourceValue = newSourceValue;
} catch (err) {
newValue = ERRORED;
node.error = err;
} finally {
consumerAfterComputation(node, prevConsumer);
}
if (oldValue !== UNSET && newValue !== ERRORED && node.equal(oldValue, newValue)) {
node.value = oldValue;
return;
}
node.value = newValue;
node.version++;
}
}))();
// src/primitives/signals/src/watch.ts
function createWatch(fn, schedule, allowSignalWrites) {
const node = Object.create(WATCH_NODE);
if (allowSignalWrites) {
node.consumerAllowSignalWrites = true;
}
node.fn = fn;
node.schedule = schedule;
const registerOnCleanup = (cleanupFn) => {
node.cleanupFn = cleanupFn;
};
function isWatchNodeDestroyed(node2) {
return node2.fn === null && node2.schedule === null;
}
function destroyWatchNode(node2) {
if (!isWatchNodeDestroyed(node2)) {
consumerDestroy(node2);
node2.cleanupFn();
node2.fn = null;
node2.schedule = null;
node2.cleanupFn = NOOP_CLEANUP_FN;
}
}
const run = () => {
if (node.fn === null) {
return;
}
if (isInNotificationPhase()) {
throw new Error(
`Schedulers cannot synchronously execute watches while scheduling.`
);
}
node.dirty = false;
if (node.hasRun && !consumerPollProducersForChange(node)) {
return;
}
node.hasRun = true;
const prevConsumer = consumerBeforeComputation(node);
try {
node.cleanupFn();
node.cleanupFn = NOOP_CLEANUP_FN;
node.fn(registerOnCleanup);
} finally {
consumerAfterComputation(node, prevConsumer);
}
};
node.ref = {
notify: () => consumerMarkDirty(node),
run,
cleanup: () => node.cleanupFn(),
destroy: () => destroyWatchNode(node),
[SIGNAL]: node
};
return node.ref;
}
var NOOP_CLEANUP_FN = () => {
};
var WATCH_NODE = /* @__PURE__ */ (() => ({
...REACTIVE_NODE,
consumerIsAlwaysLive: true,
consumerAllowSignalWrites: false,
consumerMarkedDirty: (node) => {
if (node.schedule !== null) {
node.schedule(node.ref);
}
},
hasRun: false,
cleanupFn: NOOP_CLEANUP_FN
}))();
// src/import/render3/reactivity/api.ts
function isSignal(value) {
return typeof value === "function" && value[SIGNAL] !== void 0;
}
// src/import/render3/reactivity/computed.ts
function computed(computation, options) {
const getter = createComputed(computation);
if (options?.equal) {
getter[SIGNAL].equal = options.equal;
}
if (false) {
}
return getter;
}
// src/import/render3/reactivity/signal.ts
function ɵunwrapWritableSignal(value) {
return null;
}
function signal(initialValue, options) {
const signalFn = createSignal(initialValue);
const node = signalFn[SIGNAL];
if (options?.equal) {
node.equal = options.equal;
}
signalFn.set = (newValue) => signalSetFn(node, newValue);
signalFn.update = (updateFn) => signalUpdateFn(node, updateFn);
signalFn.asReadonly = signalAsReadonlyFn.bind(
signalFn
);
if (false) {
}
return signalFn;
}
function signalAsReadonlyFn() {
const node = this[SIGNAL];
if (node.readonlyFn === void 0) {
const readonlyFn = () => this();
readonlyFn[SIGNAL] = node;
node.readonlyFn = readonlyFn;
}
return node.readonlyFn;
}
// src/import/render3/reactivity/linked_signal.ts
var identityFn = (v) => v;
function linkedSignal(optionsOrComputation, options) {
if (typeof optionsOrComputation === "function") {
const getter = createLinkedSignal(
optionsOrComputation,
identityFn,
options?.equal
);
return upgradeLinkedSignalGetter(getter);
} else {
const getter = createLinkedSignal(
optionsOrComputation.source,
optionsOrComputation.computation,
optionsOrComputation.equal
);
return upgradeLinkedSignalGetter(getter);
}
}
function upgradeLinkedSignalGetter(getter) {
if (false) {
}
const node = getter[SIGNAL];
const upgradedGetter = getter;
upgradedGetter.set = (newValue) => linkedSignalSetFn(node, newValue);
upgradedGetter.update = (updateFn) => linkedSignalUpdateFn(node, updateFn);
upgradedGetter.asReadonly = signalAsReadonlyFn.bind(
getter
);
return upgradedGetter;
}
// src/import/render3/reactivity/untracked.ts
function untracked(nonReactiveReadsFn) {
const prevConsumer = setActiveConsumer(null);
try {
return nonReactiveReadsFn();
} finally {
setActiveConsumer(prevConsumer);
}
}
// src/import/render3/reactivity/asserts.ts
function assertNotInReactiveContext(debugFn, extraContext) {
if (getActiveConsumer() !== null) {
throw new RuntimeError(
-602 /* ASSERTION_NOT_INSIDE_REACTIVE_CONTEXT */,
null
);
}
}
// src/import/di/contextual.ts
function isInInjectionContext() {
return getInjectImplementation() !== void 0 || getCurrentInjector() != null;
}
function assertInInjectionContext(debugFn) {
if (!isInInjectionContext()) {
throw new RuntimeError(-203 /* MISSING_INJECTION_CONTEXT */, null);
}
}
// src/import/linker/destroy_ref.ts
var DestroyRef = class {
/**
* @internal
* @nocollapse
*/
/**
* @internal
* @nocollapse
*/
static __NG_ENV_ID__ = (injector) => injector;
};
// src/import/util/noop.ts
function noop(...args) {
}
// src/import/change_detection/scheduling/zoneless_scheduling.ts
var NotificationSource = /* @__PURE__ */ ((NotificationSource2) => {
NotificationSource2[NotificationSource2["MarkAncestorsForTraversal"] = 0] = "MarkAncestorsForTraversal";
NotificationSource2[NotificationSource2["SetInput"] = 1] = "SetInput";
NotificationSource2[NotificationSource2["DeferBlockStateUpdate"] = 2] = "DeferBlockStateUpdate";
NotificationSource2[NotificationSource2["DebugApplyChanges"] = 3] = "DebugApplyChanges";
NotificationSource2[NotificationSource2["MarkForCheck"] = 4] = "MarkForCheck";
NotificationSource2[NotificationSource2["Listener"] = 5] = "Listener";
NotificationSource2[NotificationSource2["CustomElement"] = 6] = "CustomElement";
NotificationSource2[NotificationSource2["RenderHook"] = 7] = "RenderHook";
NotificationSource2[NotificationSource2["ViewAttached"] = 8] = "ViewAttached";
NotificationSource2[NotificationSource2["ViewDetachedFromDOM"] = 9] = "ViewDetachedFromDOM";
NotificationSource2[NotificationSource2["AsyncAnimationsLoaded"] = 10] = "AsyncAnimationsLoaded";
NotificationSource2[NotificationSource2["PendingTaskRemoved"] = 11] = "PendingTaskRemoved";
NotificationSource2[NotificationSource2["RootEffect"] = 12] = "RootEffect";
NotificationSource2[NotificationSource2["ViewEffect"] = 13] = "ViewEffect";
return NotificationSource2;
})(NotificationSource || {});
var ChangeDetectionScheduler = class {
};
var ZONELESS_ENABLED = new InjectionToken(
false ? "Zoneless enabled" : "",
{ providedIn: "root", factory: () => false }
);
var PROVIDED_ZONELESS = new InjectionToken(
false ? "Zoneless provided" : "",
{ providedIn: "root", factory: () => false }
);
var ZONELESS_SCHEDULER_DISABLED = new InjectionToken(
false ? "scheduler disabled" : ""
);
var SCHEDULE_IN_ROOT_ZONE = new InjectionToken(
false ? "run changes outside zone in root" : ""
);
// src/import/render3/reactivity/root_effect_scheduler.ts
var EffectScheduler = class _EffectScheduler {
/** @nocollapse */
static ɵprov = (
/** @pureOrBreakMyCode */
/* @__PURE__ */ ɵɵdefineInjectable({
token: _EffectScheduler,
providedIn: "root",
factory: () => new ZoneAwareEffectScheduler()
})
);
};
var ZoneAwareEffectScheduler = class {
queuedEffectCount = 0;
queues = /* @__PURE__ */ new Map();
schedule(handle) {
this.enqueue(handle);
}
remove(handle) {
const zone = handle.zone;
const queue = this.queues.get(zone);
if (!queue.has(handle)) {
return;
}
queue.delete(handle);
this.queuedEffectCount--;
}
enqueue(handle) {
const zone = handle.zone;
if (!this.queues.has(zone)) {
this.queues.set(zone, /* @__PURE__ */ new Set());
}
const queue = this.queues.get(zone);
if (queue.has(handle)) {
return;
}
this.queuedEffectCount++;
queue.add(handle);
}
/**
* Run all scheduled effects.
*
* Execution order of effects within the same zone is guaranteed to be FIFO, but there is no
* ordering guarantee between effects scheduled in different zones.
*/
flush() {
while (this.queuedEffectCount > 0) {
for (const [zone, queue] of this.queues) {
if (zone === null) {
this.flushQueue(queue);
} else {
zone.run(() => this.flushQueue(queue));
}
}
}
}
flushQueue(queue) {
for (const handle of queue) {
queue.delete(handle);
this.queuedEffectCount--;
handle.run();
}
}
};
// src/import/render3/reactivity/patch.ts
var USE_MICROTASK_EFFECT_BY_DEFAULT = false;
// src/import/error_handler.ts
var ErrorHandler = class {
/**
* @internal
*/
_console = console;
handleError(error) {
this._console.error("ERROR", error);
}
};
// src/import/pending_tasks.ts
import { BehaviorSubject } from "rxjs";
var PendingTasksInternal = class _PendingTasksInternal {
taskId = 0;
pendingTasks = /* @__PURE__ */ new Set();
get _hasPendingTasks() {
return this.hasPendingTasks.value;
}
hasPendingTasks = new BehaviorSubject(false);
add() {
if (!this._hasPendingTasks) {
this.hasPendingTasks.next(true);
}
const taskId = this.taskId++;
this.pendingTasks.add(taskId);
return taskId;
}
has(taskId) {
return this.pendingTasks.has(taskId);
}
remove(taskId) {
this.pendingTasks.delete(taskId);
if (this.pendingTasks.size === 0 && this._hasPendingTasks) {
this.hasPendingTasks.next(false);
}
}
ngOnDestroy() {
this.pendingTasks.clear();
if (this._hasPendingTasks) {
this.hasPendingTasks.next(false);
}
}
/** @nocollapse */
static ɵprov = (
/** @pureOrBreakMyCode */
/* @__PURE__ */ ɵɵdefineInjectable({
token: _PendingTasksInternal,
providedIn: "root",
factory: () => new _PendingTasksInternal()
})
);
};
var PendingTasks = class _PendingTasks {
internalPendingTasks = inject(PendingTasksInternal);
scheduler = inject(ChangeDetectionScheduler);
/**
* Adds a new task that should block application's stability.
* @returns A cleanup function that removes a task when called.
*/
add() {
const taskId = this.internalPendingTasks.add();
return () => {
if (!this.internalPendingTasks.has(taskId)) {
return;
}
this.scheduler.notify(11 /* PendingTaskRemoved */);
this.internalPendingTasks.remove(taskId);
};
}
/**
* Runs an asynchronous function and blocks the application's stability until the function completes.
*
* ```ts
* pendingTasks.run(async () => {
* const userData = await fetch('/api/user');
* this.userData.set(userData);
* });
* ```
*
* Application stability is at least delayed until the next tick after the `run` method resolves
* so it is safe to make additional updates to application state that would require UI synchronization:
*
* ```ts
* const userData = await pendingTasks.run(() => fetch('/api/user'));
* this.userData.set(userData);
* ```
*
* @param fn The asynchronous function to execute
*/
async run(fn) {
const removeTask = this.add();
try {
return await fn();
} finally {
removeTask();
}
}
/** @nocollapse */
static ɵprov = (
/** @pureOrBreakMyCode */
/* @__PURE__ */ ɵɵdefineInjectable({
token: _PendingTasks,
providedIn: "root",
factory: () => new _PendingTasks()
})
);
};
// src/import/render3/reactivity/microtask_effect.ts
var MicrotaskEffectScheduler = class _MicrotaskEffectScheduler extends ZoneAwareEffectScheduler {
pendingTasks = inject(PendingTasksInternal);
taskId = null;
schedule(effect3) {
super.schedule(effect3);
if (this.taskId === null) {
this.taskId = this.pendingTasks.add();
queueMicrotask(() => this.flush());
}
}
flush() {
try {
super.flush();
} finally {
if (this.taskId !== null) {
this.pendingTasks.remove(this.taskId);
this.taskId = null;
}
}
}
/** @nocollapse */
static ɵprov = (
/** @pureOrBreakMyCode */
/* @__PURE__ */ ɵɵdefineInjectable({
token: _MicrotaskEffectScheduler,
providedIn: "root",
factory: () => new _MicrotaskEffectScheduler()
})
);
};
var EffectHandle = class {
constructor(scheduler, effectFn, zone, destroyRef, injector, allowSignalWrites) {
this.scheduler = scheduler;
this.effectFn = effectFn;
this.zone = zone;
this.injector = injector;
this.watcher = createWatch(
(onCleanup) => this.runEffect(onCleanup),
() => this.schedule(),
allowSignalWrites
);
this.unregisterOnDestroy = destroyRef?.onDestroy(() => this.destroy());
}
unregisterOnDestroy;
watcher;
runEffect(onCleanup) {
try {
this.effectFn(onCleanup);
} catch (err) {
const errorHandler = this.injector.get(ErrorHandler, null, {
optional: true
});
errorHandler?.handleError(err);
}
}
run() {
this.watcher.run();
}
schedule() {
this.scheduler.schedule(this);
}
destroy() {
this.watcher.destroy();
this.unregisterOnDestroy?.();
}
};
function effect() {
}
fu