static-injector
Version:
Angular 依赖注入独立版本;Angular dependency injection standalone version
1,599 lines (1,551 loc) • 65.9 kB
JavaScript
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/import/index.ts
var import_exports = {};
__export(import_exports, {
ChangeDetectionScheduler: () => ChangeDetectionScheduler,
ChangeDetectionSchedulerImpl: () => ChangeDetectionSchedulerImpl,
DecoratorFlags: () => DecoratorFlags,
DestroyRef: () => DestroyRef,
EnvironmentInjector: () => EnvironmentInjector,
ErrorHandler: () => ErrorHandler,
INJECTOR_SCOPE: () => INJECTOR_SCOPE,
INTERNAL_APPLICATION_ERROR_HANDLER: () => INTERNAL_APPLICATION_ERROR_HANDLER,
Inject: () => Inject,
Injectable: () => Injectable,
InjectionToken: () => InjectionToken,
Injector: () => Injector,
InternalInjectFlags: () => InternalInjectFlags,
NG_INJ_DEF: () => NG_INJ_DEF,
NG_PROV_DEF: () => NG_PROV_DEF,
NG_TEMP_TOKEN_PATH: () => NG_TEMP_TOKEN_PATH,
NotificationSource: () => NotificationSource,
NullInjector: () => NullInjector,
Optional: () => Optional,
PROVIDED_ZONELESS: () => PROVIDED_ZONELESS,
PendingTasks: () => PendingTasks,
PendingTasksInternal: () => PendingTasksInternal,
R3Injector: () => R3Injector,
RetrievingInjector: () => RetrievingInjector,
RootStaticInjectOptions: () => RootStaticInjectOptions,
SCHEDULE_IN_ROOT_ZONE: () => SCHEDULE_IN_ROOT_ZONE,
SOURCE: () => SOURCE,
Self: () => Self,
SkipSelf: () => SkipSelf,
StaticInjectOptions: () => StaticInjectOptions,
THROW_IF_NOT_FOUND: () => THROW_IF_NOT_FOUND,
ZONELESS_ENABLED: () => ZONELESS_ENABLED,
ZONELESS_SCHEDULER_DISABLED: () => ZONELESS_SCHEDULER_DISABLED,
assertNotDestroyed: () => assertNotDestroyed,
assertNotInReactiveContext: () => assertNotInReactiveContext,
attachInjectFlag: () => attachInjectFlag,
catchInjectorError: () => catchInjectorError,
computed: () => computed,
convertToBitFlags: () => convertToBitFlags,
createInjector: () => createInjector2,
createRootInjector: () => createRootInjector,
effect: () => effect,
formatError: () => formatError,
getCurrentInjector: () => getCurrentInjector,
getInheritedInjectableDef: () => getInheritedInjectableDef,
getInjectFlag: () => getInjectFlag,
getInjectableDef: () => getInjectableDef,
getInjectorDef: () => getInjectorDef,
getNullInjector: () => getNullInjector,
inject: () => inject,
injectArgs: () => injectArgs,
injectInjectorOnly: () => injectInjectorOnly,
isInjectable: () => isInjectable,
isSignal: () => isSignal,
linkedSignal: () => linkedSignal,
providerToFactory: () => providerToFactory,
resource: () => resource,
setCurrentInjector: () => setCurrentInjector,
signal: () => signal,
untracked: () => untracked2,
ɵEffectScheduler: () => EffectScheduler,
ɵSIGNAL: () => SIGNAL,
ɵunwrapWritableSignal: () => ɵunwrapWritableSignal,
ɵɵdefineInjectable: () => ɵɵdefineInjectable,
ɵɵdefineInjector: () => ɵɵdefineInjector,
ɵɵinject: () => ɵɵinject,
ɵɵinvalidFactory: () => ɵɵinvalidFactory,
ɵɵinvalidFactoryDep: () => ɵɵinvalidFactoryDep
});
module.exports = __toCommonJS(import_exports);
// 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 formatRuntimeErrorCode(code) {
return `NG0${Math.abs(code)}`;
}
function formatRuntimeError(code, message) {
const fullCode = formatRuntimeErrorCode(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/render3/errors_di.ts
function throwCyclicDependencyError(token, path) {
throw new RuntimeError(-200 /* CYCLIC_DI_DEPENDENCY */, token);
}
function throwProviderNotFoundError(token, injectorName) {
const errorMessage = void 0;
throw new RuntimeError(-201 /* PROVIDER_NOT_FOUND */, errorMessage);
}
// src/import/util/property.ts
function getClosureSafeProperty(objWithPropertyToExtract) {
for (const key in objWithPropertyToExtract) {
if (objWithPropertyToExtract[key] === getClosureSafeProperty) {
return key;
}
}
throw Error("");
}
// 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?.[NG_PROV_DEF] ?? null;
if (def) {
return def;
} else {
return null;
}
}
function getInjectorDef(type) {
return type && type.hasOwnProperty(NG_INJ_DEF) ? 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/di/interface/injector.ts
var DecoratorFlags = /* @__PURE__ */ ((DecoratorFlags2) => {
DecoratorFlags2[DecoratorFlags2["Inject"] = -1] = "Inject";
return DecoratorFlags2;
})(DecoratorFlags || {});
var InternalInjectFlags = /* @__PURE__ */ ((InternalInjectFlags2) => {
InternalInjectFlags2[InternalInjectFlags2["Default"] = 0] = "Default";
InternalInjectFlags2[InternalInjectFlags2["Host"] = 1] = "Host";
InternalInjectFlags2[InternalInjectFlags2["Self"] = 2] = "Self";
InternalInjectFlags2[InternalInjectFlags2["SkipSelf"] = 4] = "SkipSelf";
InternalInjectFlags2[InternalInjectFlags2["Optional"] = 8] = "Optional";
InternalInjectFlags2[InternalInjectFlags2["ForPipe"] = 16] = "ForPipe";
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/primitives/di/src/injector.ts
var _currentInjector = void 0;
function getCurrentInjector() {
return _currentInjector;
}
function setCurrentInjector(injector) {
const former = _currentInjector;
_currentInjector = injector;
return former;
}
// src/primitives/di/src/not_found.ts
var NOT_FOUND = Symbol("NotFound");
var NotFoundError = class extends Error {
name = "ɵNotFound";
constructor(message) {
super(message);
}
};
function isNotFound(e) {
return e === NOT_FOUND || e?.name === "ɵNotFound";
}
// 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 RetrievingInjector = class {
constructor(injector) {
this.injector = injector;
}
retrieve(token, options) {
const flags = convertToBitFlags(options) || 0 /* Default */;
try {
return this.injector.get(
token,
// When a dependency is requested with an optional flag, DI returns null as the default value.
flags & 8 /* Optional */ ? null : THROW_IF_NOT_FOUND,
flags
);
} catch (e) {
if (isNotFound(e)) {
return e;
}
throw e;
}
}
};
var NG_TEMP_TOKEN_PATH = "ngTempTokenPath";
var NG_TOKEN_PATH = "ngTokenPath";
var NEW_LINE = /\n/gm;
var NO_NEW_LINE = "ɵ";
var SOURCE = "__source";
function injectInjectorOnly(token, flags = 0 /* Default */) {
const currentInjector = getCurrentInjector();
if (currentInjector === void 0) {
throw new RuntimeError(-203 /* MISSING_INJECTION_CONTEXT */, void 0);
} else if (currentInjector === null) {
return injectRootLimpMode(token, void 0, flags);
} else {
const options = convertToInjectOptions(flags);
const value = currentInjector.retrieve(token, options);
if (isNotFound(value)) {
if (options.optional) {
return null;
}
throw value;
}
return value;
}
}
function ɵɵinject(token, flags = 0 /* Default */) {
return (getInjectImplementation() || injectInjectorOnly)(resolveForwardRef(token), flags);
}
function ɵɵinvalidFactoryDep(index) {
throw new RuntimeError(202 /* INVALID_FACTORY_DEPENDENCY */, void 0);
}
function inject(token, options) {
return ɵɵinject(token, convertToBitFlags(options));
}
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 convertToInjectOptions(flags) {
return {
optional: !!(flags & 8 /* Optional */),
host: !!(flags & 1 /* Host */),
self: !!(flags & 2 /* Self */),
skipSelf: !!(flags & 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 */, void 0);
}
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 NotFoundError(`NullInjectorError: No provider for ${stringify(token)}!`);
throw error;
}
return notFoundValue;
}
};
// src/import/di/provider_collection.ts
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, { self: true }));
}
/**
* 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;
retrieve(token, options) {
const flags = convertToBitFlags(options) || 0 /* Default */;
try {
return this.get(
token,
// When a dependency is requested with an optional flag, DI returns null as the default value.
THROW_IF_NOT_FOUND,
flags
);
} catch (e) {
if (isNotFound(e)) {
return e;
}
throw e;
}
}
/**
* 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, options) {
assertNotDestroyed(this);
if (token.hasOwnProperty(NG_ENV_ID)) {
return token[NG_ENV_ID](this);
}
const flags = convertToBitFlags(options);
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 (isNotFound(e)) {
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, { self: true });
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 (record.value === CIRCULAR) {
throwCyclicDependencyError(stringify(token));
} 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 */, void 0);
}
if (token instanceof Function) {
return getUndecoratedInjectableFactory(token);
}
throw new RuntimeError(204 /* INVALID_INJECTION_TOKEN */, void 0);
}
function getUndecoratedInjectableFactory(token) {
const paramLength = token.length;
if (paramLength > 0) {
throw new RuntimeError(204 /* INVALID_INJECTION_TOKEN */, void 0);
}
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 */, void 0);
}
}
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.ngMetadataName === "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];
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 postProducerCreatedFn = null;
var SIGNAL = /* @__PURE__ */ Symbol("SIGNAL");
function setActiveConsumer(consumer) {
const prev = activeConsumer;
activeConsumer = consumer;
return prev;
}
function getActiveConsumer() {
return activeConsumer;
}
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;
}
function runPostProducerCreatedFn(node) {
postProducerCreatedFn?.(node);
}
// src/primitives/signals/src/computed.ts
function createComputed(computation, equal) {
const node = Object.create(COMPUTED_NODE);
node.computation = computation;
if (equal !== void 0) {
node.equal = equal;
}
const computed2 = () => {
producerUpdateValueVersion(node);
producerAccessed(node);
if (node.value === ERRORED) {
throw node.error;
}
return node.value;
};
computed2[SIGNAL] = node;
if (false) {
const debugName = node.debugName ? " (" + node.debugName + ")" : "";
computed2.toString = () => `[Computed${debugName}: ${node.value}]`;
}
runPostProducerCreatedFn(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(false ? "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, equal) {
const node = Object.create(SIGNAL_NODE);
node.value = initialValue;
if (equal !== void 0) {
node.equal = equal;
}
const getter = () => signalGetFn(node);
getter[SIGNAL] = node;
if (false) {
const debugName = node.debugName ? " (" + node.debugName + ")" : "";
getter.toString = () => `[Signal${debugName}: ${node.value}]`;
}
runPostProducerCreatedFn(node);
const set = (newValue) => signalSetFn(node, newValue);
const update = (updateFn) => signalUpdateFn(node, updateFn);
return [getter, set, update];
}
function signalGetFn(node) {
producerAccessed(node);
return node.value;
}
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?.(node);
}
// 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;
if (false) {
const debugName = node.debugName ? " (" + node.debugName + ")" : "";
getter.toString = () => `[LinkedSignal${debugName}: ${node.value}]`;
}
runPostProducerCreatedFn(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,
kind: "linkedSignal",
producerMustRecompute(node) {
return node.value === UNSET || node.value === COMPUTING;
},
producerRecomputeValue(node) {
if (node.value === COMPUTING) {
throw new Error(false ? "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/untracked.ts
function untracked(nonReactiveReadsFn) {
const prevConsumer = setActiveConsumer(null);
try {
return nonReactiveReadsFn();
} finally {
setActiveConsumer(prevConsumer);
}
}
// 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, options?.equal);
if (false) {
}
return getter;
}
// src/import/render3/reactivity/signal.ts
function ɵunwrapWritableSignal(value) {
return null;
}
function signal(initialValue, options) {
const [get, set, update] = createSignal(initialValue, options?.equal);
const signalFn = get;
const node = signalFn[SIGNAL];
signalFn.set = set;
signalFn.update = update;
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 untracked2(nonReactiveReadsFn) {
return untracked(nonReactiveReadsFn);
}
// src/import/render3/reactivity/asserts.ts
function assertNotInReactiveContext(debugFn, extraContext) {
if (getActiveConsumer() !== null) {
throw new RuntimeError(-602 /* ASSERTION_NOT_INSIDE_REACTIVE_CONTEXT */, void 0);
}
}
// 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("", { providedIn: "root", factory: () => false });
var PROVIDED_ZONELESS = new InjectionToken("", { providedIn: "root", factory: () => false });
var ZONELESS_SCHEDULER_DISABLED = new InjectionToken("");
var SCHEDULE_IN_ROOT_ZONE = new InjectionToken("");
// 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 {
dirtyEffectCount = 0;
queues = /* @__PURE__ */ new Map();
add(handle) {
this.enqueue(handle);
this.schedule(handle);
}
schedule(handle) {
if (!handle.dirty) {
return;
}
this.dirtyEffectCount++;
}
remove(handle) {
const zone = handle.zone;
const queue = this.queues.get(zone);
if (!queue.has(handle)) {
return;
}
queue.delete(handle);
if (handle.dirty) {
this.dirtyEffectCount--;
}
}
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;
}
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.dirtyEffectCount > 0) {
let ranOneEffect = false;
for (const [zone, queue] of this.queues) {
if (zone === null) {
ranOneEffect ||= this.flushQueue(queue);
} else {
ranOneEffect ||= zone.run(() => this.flushQueue(queue));
}
}
if (!ranOneEffect) {
this.dirtyEffectCount = 0;
}
}
}
flushQueue(queue) {
let ranOneEffect = false;
for (const handle of queue) {
if (!handle.dirty) {
continue;
}
this.dirtyEffectCount--;
ranOneEffect = true;
handle.run();
}
return ranOneEffect;
}
};
// src/import/render3/reactivity/effect.ts
var EffectRefImpl = class {
[SIGNAL];
constructor(node) {
this[SIGNAL] = node;
}
destroy() {
this[SIGNAL].destroy();
}
};
function effect(effectFn, options) {
if (false) {
assertInInjectionContext(effect);
}
if (false) {
console.warn(`The 'allowSignalWrites' flag is deprecated and no longer impacts effect() (writes are always allowed)`);
}
const injector = options?.injector ?? inject(Injector);
const destroyRef = options?.manualCleanup !== true ? injector.get(DestroyRef) : null;
let node;
const notifier = injector.get(ChangeDetectionScheduler);
node = createRootEffect(effectFn, injector.get(EffectScheduler), notifier);
node.injector = injector;
if (destroyRef !== null) {
node.onDestroyFn = destroyRef.onDestroy(() => node.destroy());
}
const effectRef = new EffectRefImpl(node);
return effectRef;
}
var BASE_EFFECT_NODE = /* @__PURE__ */ (() => ({
...REACTIVE_NODE,
consumerIsAlwaysLive: true,
consumerAllowSignalWrites: true,
dirty: true,
hasRun: false,
cleanupFns: void 0,
zone: null,
kind: "effect",
onDestroyFn: noop,
run() {
this.dirty = false;
if (false) {
throw new Error(`Schedulers cannot synchronously execute watches while scheduling.`);
}
if (this.hasRun && !consumerPollProducersForChange(this)) {
return;
}
this.hasRun = true;
const registerCleanupFn = (cleanupFn) => (this.cleanupFns ??= []).push(cleanupFn);
const prevNode = consumerBeforeComputation(this);
try {
this.maybeCleanup();
this.fn(registerCle