{"version":3,"file":"ngx-reactivetoolkit.mjs","sources":["../../src/decorators/decorators.ts","../../src/until-destroy/ivy.ts","../../src/until-destroy/internals.ts","../../src/until-destroy/until-destroy.decorator.ts","../../src/until-destroy/take-until-destroy.operator.ts","../../ngx-reactivetoolkit.ts"],"sourcesContent":["import { SimpleChanges } from '@angular/core';\nimport { Subject, ReplaySubject } from 'rxjs';\nimport { filter, map, startWith } from 'rxjs/operators';\n\n// These decorators are all about utils to turn lifecycle events into streams\n/*\n    The Destroy decorator creates a stream that gets nexted when the ngOnDestroy is being called.\n    A use case might be to avoid memoryleaks by using the takeUntil operator\n    @Component({\n        selector: 'my-component',\n        template: `...`,\n    })\n    export class HelloComponent {\n        @Destroy() destroy$;\n\n        constructor() {\n            Observable.interval(500)\n                .takeUntil(this.destroy$)\n                .subscribe(e => console.log(e));\n        }\n    }\n*/\n\nexport function Destroy() {\n  return function (target: any, key: string) {\n    const oldNgOnDestroy = target.constructor.prototype.ngOnDestroy;\n    if (!oldNgOnDestroy) {\n      throw new Error(\n        `ngOnDestroy must be implemented for ${target.constructor.name}`\n      );\n    }\n\n    const accessor = `${key}$`;\n    const secret = `_${key}$`;\n\n    Object.defineProperty(target, accessor, {\n      get: function () {\n        if (this[secret]) {\n          return this[secret];\n        }\n        this[secret] = new Subject();\n        return this[secret];\n      }\n    });\n    Object.defineProperty(target, key, {\n      get: function () {\n        return this[accessor];\n      },\n      set: function () {\n        throw new Error(\n          'You cannot set this property in the Component if you use @Destroy'\n        );\n      }\n    });\n\n    target.constructor.prototype.ngOnDestroy = function () {\n      if (oldNgOnDestroy) {\n        oldNgOnDestroy.apply(this, arguments);\n      }\n      this[accessor].next(true);\n      this[accessor].complete();\n    };\n  };\n}\n\n/*\n    The Changes decorator creates a stream that gets nexted when the ngOnDestroy is being called.\n    A use case might be to avoid memoryleaks by using the takeUntil operator\n    @Component({\n        selector: 'my-component',\n        template: `...`,\n    })\n    export class HelloComponent {\n        @Changes() changes$;\n\n        constructor() {\n            this.changes$.subscribe(e => console.log(e));\n        }\n    }\n*/\n\nexport function Changes(inputProp?: string, initialValue?: any) {\n  return function (target: any, key: string): any {\n    const oldNgOnChanges = target.constructor.prototype.ngOnChanges;\n\n    if (!oldNgOnChanges) {\n      throw new Error(\n        `ngOnChanges must be implemented for ${target.constructor.name}`\n      );\n    }\n\n    target.ngOnChanges = function (simpleChanges: SimpleChanges) {\n      if (oldNgOnChanges) {\n        oldNgOnChanges.apply(this, [simpleChanges]);\n      }\n\n      this[accessorSub].next(simpleChanges);\n    };\n\n    const secretSub = `_${key}$Sub`;\n    const secretObs = `_${key}$Obs`;\n    const accessorSub = `${key}$Sub`;\n    const accessorObs = `${key}$Obs`;\n\n    Object.defineProperty(target, accessorSub, {\n      get: function () {\n        if (this[secretSub]) {\n          return this[secretSub];\n        }\n\n        this[secretSub] = new ReplaySubject(1);\n\n        return this[secretSub];\n      }\n    });\n\n    Object.defineProperty(target, accessorObs, {\n      get: function () {\n        if (this[secretObs]) {\n          return this[secretObs];\n        }\n\n        this[secretObs] = inputProp\n          ? this[accessorSub].pipe(\n              filter(changes => !!changes && changes[inputProp]),\n              map(changes => changes[inputProp].currentValue),\n              s =>\n                initialValue !== undefined ? s.pipe(startWith(initialValue)) : s\n            )\n          : this[accessorSub].asObservable();\n\n        return this[secretObs];\n      }\n    });\n\n    return {\n      get: function () {\n        return this[accessorObs];\n      },\n      set: function () {\n        throw new Error(\n          'You cannot set this property in the Component if you use @Changes'\n        );\n      }\n    };\n  };\n}\n","import { Type, ɵNG_PIPE_DEF, ɵPipeDef } from '@angular/core';\n\nconst NG_PIPE_DEF = ɵNG_PIPE_DEF as 'ɵpipe';\n\n// Angular doesn't expose publicly `PipeType` but it actually has it.\nexport interface PipeType<T> extends Type<T> {\n  ɵpipe: ɵPipeDef<T>;\n}\n\nexport function isPipe<T>(target: any): target is PipeType<T> {\n  return !!target[NG_PIPE_DEF];\n}\n","import { InjectableType, ɵDirectiveType, ɵComponentType } from '@angular/core';\nimport { Subject } from 'rxjs';\n\nimport { PipeType } from './ivy';\n\nexport function isFunction(target: unknown) {\n  return typeof target === 'function';\n}\n\n/**\n * Applied to instances and stores `Subject` instance when\n * no custom destroy method is provided.\n */\nconst DESTROY: unique symbol = Symbol('__destroy');\n\n/**\n * Applied to definitions and informs that class is decorated\n */\nexport const DECORATOR_APPLIED: unique symbol = Symbol('__decoratorApplied');\n\n/**\n * If we use the `untilDestroyed` operator multiple times inside the single\n * instance providing different `destroyMethodName`, then all streams will\n * subscribe to the single subject. If any method is invoked, the subject will\n * emit and all streams will be unsubscribed. We wan't to prevent this behavior,\n * thus we store subjects under different symbols.\n */\nexport function getSymbol<T>(destroyMethodName?: keyof T): symbol {\n  if (typeof destroyMethodName === 'string') {\n    return Symbol(`__destroy__${destroyMethodName}`);\n  } else {\n    return DESTROY;\n  }\n}\n\nexport function markAsDecorated<T>(\n  type: InjectableType<T> | PipeType<T> | ɵDirectiveType<T> | ɵComponentType<T>\n): void {\n  // Store this property on the prototype if it's an injectable class, component or directive.\n  // We will be able to handle class extension this way.\n  type.prototype[DECORATOR_APPLIED] = true;\n}\n\nexport function createSubjectOnTheInstance(\n  instance: any,\n  symbol: symbol\n): void {\n  if (!instance[symbol]) {\n    instance[symbol] = new Subject<void>();\n  }\n}\n\nexport function completeSubjectOnTheInstance(\n  instance: any,\n  symbol: symbol\n): void {\n  if (instance[symbol]) {\n    instance[symbol].next();\n    instance[symbol].complete();\n    // We also have to re-assign this property thus in the future\n    // we will be able to create new subject on the same instance.\n    instance[symbol] = null;\n  }\n}\n","import {\n  InjectableType,\n  ɵComponentType as ComponentType,\n  ɵDirectiveType as DirectiveType\n} from '@angular/core';\nimport { SubscriptionLike } from 'rxjs';\n\nimport { PipeType, isPipe } from './ivy';\nimport {\n  getSymbol,\n  isFunction,\n  completeSubjectOnTheInstance,\n  markAsDecorated\n} from './internals';\n\nfunction unsubscribe(property: SubscriptionLike | undefined): void {\n  property && isFunction(property.unsubscribe) && property.unsubscribe();\n}\n\nfunction unsubscribeIfPropertyIsArrayLike(property: any[]): void {\n  Array.isArray(property) && property.forEach(unsubscribe);\n}\n\nfunction decorateNgOnDestroy(ngOnDestroy: (() => void) | null | undefined) {\n  return function (this: any) {\n    // Invoke the original `ngOnDestroy` if it exists\n    ngOnDestroy && ngOnDestroy.call(this);\n\n    // It's important to use `this` instead of caching instance\n    // that may lead to memory leaks\n    completeSubjectOnTheInstance(this, getSymbol());\n  };\n}\n\nfunction decorateProviderDirectiveOrComponent<T>(\n  type: InjectableType<T> | DirectiveType<T> | ComponentType<T>\n): void {\n  type.prototype.ngOnDestroy = decorateNgOnDestroy(type.prototype.ngOnDestroy);\n}\n\nfunction decoratePipe<T>(type: PipeType<T>): void {\n  const def = type.ɵpipe;\n  def.onDestroy = decorateNgOnDestroy(def.onDestroy);\n}\n\nexport function UntilDestroy(): ClassDecorator {\n  return (type: any) => {\n    if (isPipe(type)) {\n      decoratePipe(type);\n    } else {\n      decorateProviderDirectiveOrComponent(type);\n    }\n\n    markAsDecorated(type);\n  };\n}\n","import { Observable } from 'rxjs';\nimport { takeUntil } from 'rxjs/operators';\n\nimport {\n  DECORATOR_APPLIED,\n  getSymbol,\n  isFunction,\n  createSubjectOnTheInstance,\n  completeSubjectOnTheInstance\n} from './internals';\n\n// This will be provided through Terser global definitions by Angular CLI. This will\n// help to tree-shake away the code unneeded for production bundles.\ndeclare const ngDevMode: boolean;\n\nfunction overrideNonDirectiveInstanceMethod(\n  instance: any,\n  destroyMethodName: string,\n  symbol: symbol\n): void {\n  const originalDestroy = instance[destroyMethodName];\n\n  if (ngDevMode && isFunction(originalDestroy) === false) {\n    throw new Error(\n      `${instance.constructor.name} is using takeUntilDestroy but doesn't implement ${destroyMethodName}`\n    );\n  }\n\n  createSubjectOnTheInstance(instance, symbol);\n\n  instance[destroyMethodName] = function () {\n    originalDestroy.apply(this, arguments);\n    completeSubjectOnTheInstance(this, symbol);\n    // We have to re-assign this property back to the original value.\n    // If the `untilDestroyed` operator is called for the same instance\n    // multiple times, then we will be able to get the original\n    // method again and not the patched one.\n    instance[destroyMethodName] = originalDestroy;\n  };\n}\n\nexport function takeUntilDestroy<T>(instance: T, destroyMethodName?: keyof T) {\n  return <U>(source: Observable<U>) => {\n    const symbol = getSymbol<T>(destroyMethodName);\n\n    // If `destroyMethodName` is passed then the developer applies\n    // this operator to something non-related to Angular DI system\n    if (typeof destroyMethodName === 'string') {\n      overrideNonDirectiveInstanceMethod(instance, destroyMethodName, symbol);\n    } else {\n      ngDevMode && ensureClassIsDecorated(instance);\n      createSubjectOnTheInstance(instance, symbol);\n    }\n\n    return source.pipe(takeUntil<U>((instance as any)[symbol]));\n  };\n}\n\nfunction ensureClassIsDecorated(instance: InstanceType<any>): never | void {\n  const prototype = Object.getPrototypeOf(instance);\n  const missingDecorator = !(DECORATOR_APPLIED in prototype);\n\n  if (missingDecorator) {\n    throw new Error(\n      'takeUntilDestroy operator cannot be used inside directives or ' +\n        'components or providers that are not decorated with UntilDestroy decorator'\n    );\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;AAIA;AACA;;;;;;;;;;;;;;;;;SAkBgB,OAAO;IACrB,OAAO,UAAU,MAAW,EAAE,GAAW;QACvC,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC;QAChE,IAAI,CAAC,cAAc,EAAE;YACnB,MAAM,IAAI,KAAK,CACb,uCAAuC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CACjE,CAAC;SACH;QAED,MAAM,QAAQ,GAAG,GAAG,GAAG,GAAG,CAAC;QAC3B,MAAM,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;QAE1B,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE;YACtC,GAAG,EAAE;gBACH,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE;oBAChB,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;iBACrB;g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