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

fix(angular): type resolution with strict templates #209

Conversation

sean-perkins
Copy link
Collaborator

@sean-perkins sean-perkins commented Dec 2, 2021

Updates the implementation pattern for event emitters in the Angular output target to solve inaccurate type detection for strict templates and Angular Language Service. This also eliminates the dependency on rxjs with the implementation pattern. Confirmed that this change does not regress the solution to prevent duplicate event emissions.

Current version output:

export declare interface IonCheckbox extends Components.IonCheckbox {}

@ProxyCmp({
  tagName: 'ion-checkbox',
  customElement: undefined,
  inputs: ['checked', 'color', 'disabled', 'indeterminate', 'mode', 'name', 'value']
})
@Component({
  selector: 'ion-checkbox',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: '<ng-content></ng-content>',
  inputs: ['checked', 'color', 'disabled', 'indeterminate', 'mode', 'name', 'value']
})
export class IonCheckbox {
  /**
   * Emitted when the checked property has changed. 
   */
  @Output() ionChange = new EventEmitter<CustomEvent<ICheckboxCheckboxChangeEventDetail>>();
  /**
   * Emitted when the checkbox has focus. 
   */
  @Output() ionFocus = new EventEmitter<CustomEvent<void>>();
  /**
   * Emitted when the checkbox loses focus. 
   */
  @Output() ionBlur = new EventEmitter<CustomEvent<void>>();


  protected el: HTMLElement;
  constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
    c.detach();
    this.el = r.nativeElement;
  }
}

Breaking change

Before this would work:

@ViewChild(IonSlides, { static: true }) slides: IonSlides;

this.slides.ionSlideDidChange.subscribe(() => {
  console.log('slideDidChange');
});

After, implementers will need to use rxjs to convert the DOM event:

import { fromEvent } from 'rxjs';

@ViewChild(IonSlides, { static: true, read: ElementRef }) slides: IonSlides;

fromEvent(this.slides, 'ionSlideDidChange').subscribe(() => {
  console.log('slideDidChange');
});

Fixes issue in Framework repo: ionic-team/ionic-framework#24245

@sean-perkins sean-perkins changed the title fix(angular-output-target): type resolution with strict templates fix(angular): type resolution with strict templates Dec 2, 2021
@sean-perkins sean-perkins removed the request for review from willmartian December 2, 2021 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant