Skip to content

[BUG] disableLifeCycleHooks is not respected with pipes #1369

Closed

Description

@Blackbaud-TrevorBurch
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

Activity

  1. Blackbaud-TrevorBurch commented on Aug 14, 2023

    @Blackbaud-TrevorBurch
    Author

    I'm also seeing this behavior with services.

  2. added a commit that references this issue on Jul 15, 2024
    753b74d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions