Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] disableLifeCycleHooks is not respected with pipes #1369

Closed
Blackbaud-TrevorBurch opened this issue Aug 4, 2023 · 1 comment
Closed
Assignees

Comments

@Blackbaud-TrevorBurch
Copy link

Overview of the issue

Pipes can use Angular Life Cycle Hooks; however, I am able to still see ngOnDestroy when compodoc is ran on our pipe

Operating System, Node.js, npm, compodoc version(s)

Window
Node - 18.14.2
NPM - 9.5.0
compodoc - 1.1.21

Angular configuration, a package.json file in the root folder
"@angular-devkit/build-angular": "16.1.6",
"@angular-devkit/core": "16.1.6",
"@angular-devkit/schematics": "16.1.6",
"@angular-eslint/eslint-plugin": "16.1.0",
"@angular-eslint/eslint-plugin-template": "16.1.0",
"@angular-eslint/template-parser": "16.1.0",
"@angular/cli": "16.1.6",
"@angular/compiler-cli": "16.1.7",
"@angular/language-service": "16.1.7",
"@compodoc/compodoc": "1.1.19"
Compodoc installed globally or locally ?

Locally

If possible sourcecode of the file where it breaks
import { OnDestroy, Pipe, PipeTransform } from '@angular/core';
import { SkyAppLocaleInfo, SkyAppLocaleProvider } from '@skyux/i18n';

import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

import { SkyDateFormatUtility } from './date-format-utility';

/**
 * Formats date values according to locale rules.
 * @example
 * ```markup
 * {{ myDate | skyDate }}
 * {{ myDate | skyDate:'medium' }}
 * {{ myDate | skyDate:'medium':'en-CA' }}
 * ```
 */
@Pipe({
  name: 'skyDate',
  pure: false,
})
export class SkyDatePipe implements OnDestroy, PipeTransform {
  #defaultFormat = 'short';

  #format: string | undefined;

  #defaultLocale = 'en-US';

  #locale: string | undefined;

  #value: any;

  #formattedValue: string | undefined;

  #ngUnsubscribe = new Subject<void>();

  constructor(localeProvider: SkyAppLocaleProvider) {
    localeProvider
      .getLocaleInfo()
      .pipe(takeUntil(this.#ngUnsubscribe))
      .subscribe((localeInfo: SkyAppLocaleInfo) => {
        this.#defaultLocale = localeInfo.locale;
        this.#updateFormattedValue();
      });
  }

  public ngOnDestroy(): void {
    this.#ngUnsubscribe.next();
    this.#ngUnsubscribe.complete();
  }

  /**
   * Transforms a date value using locale and format rules.
   * @param value Specifies the date value to transform.
   * @param format Specifies the format to apply to the transform. The format string is
   * constructed by a series of symbols that represent date-time values. The symbols are
   * identical to [Angular's `DatePipe`](https://angular.io/api/common/DatePipe#pre-defined-format-options) format options.
   * @param locale Specifies the locale code to use in the transform.
   */
  public transform(value: any, format?: string, locale?: string): string {
    this.#value = value;
    this.#format = format;
    this.#locale = locale;

    this.#updateFormattedValue();

    return this.#formattedValue ?? '';
  }

  #updateFormattedValue(): void {
    const locale = this.#locale || this.#defaultLocale;
    const format = this.#format || this.#defaultFormat;

    this.#formattedValue = SkyDateFormatUtility.format(
      locale,
      this.#value,
      format
    );
  }
}

If possible your terminal logs before the error

N/A

Motivation for or Use Case

We do not want to publicly document the lifecycle hook for this pipe.

Reproduce the error

Add a pipe with a lifecycle hook and run compodoc with disableLifeCycleHooks

Related issues

N/A

Suggest a Fix
@Blackbaud-TrevorBurch
Copy link
Author

I'm also seeing this behavior with services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants