in src/AutoSubscriptions.ts [341:392]
export function disableWarnings<T extends Function>(target: InstanceTarget,
methodName: string,
descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> {
const targetWithMetadata = instanceTargetToInstanceTargetWithMetadata(target);
// Record that the target is decorated.
const metaForMethod = getMethodMetadata(targetWithMetadata, methodName);
metaForMethod.hasAutoSubscribeDecorator = true;
if (!Options.development) {
// Warnings are already disabled for production.
return descriptor;
}
// Save the method being decorated. Note this might be another decorator method.
const existingMethod = descriptor.value!!!;
// Note: we need to be given 'this', so cannot use '=>' syntax.
// Note: T might have other properties (e.g. T = { (): void; bar: number; }). We don't support that and need a cast.
descriptor.value = function DisableWarnings(this: any, ...args: any[]) {
assert(targetWithMetadata.__resubMetadata.__decorated, `Missing @AutoSubscribeStore class decorator: "${ methodName }"`);
// Just call the method if no handler is setup.
const scopedHandleWrapper = handlerWrapper;
if (!scopedHandleWrapper || scopedHandleWrapper.useAutoSubscriptions === AutoOptions.None) {
return existingMethod.apply(this, args);
}
let wasInAutoSubscribe: boolean;
let wasUseAutoSubscriptions: AutoOptions;
const result = _tryFinally(() => {
// Any further @warnIfAutoSubscribeEnabled methods are safe.
wasInAutoSubscribe = scopedHandleWrapper.inAutoSubscribe;
scopedHandleWrapper.inAutoSubscribe = true;
// If in a forbidAutoSubscribeWrapper method, any further @autoSubscribe methods are safe.
wasUseAutoSubscriptions = scopedHandleWrapper.useAutoSubscriptions;
if (scopedHandleWrapper.useAutoSubscriptions === AutoOptions.Forbid) {
scopedHandleWrapper.useAutoSubscriptions = AutoOptions.None;
}
return existingMethod.apply(this, args);
}, () => {
scopedHandleWrapper.inAutoSubscribe = wasInAutoSubscribe;
scopedHandleWrapper.useAutoSubscriptions = wasUseAutoSubscriptions;
});
return result;
} as any as T;
return descriptor;
}