@molecule/lifecycle-decorator

Provides rxjs streams for all Ionic and Angular lifecycle hooks.

Stats

StarsIssuesVersionUpdatedCreatedSize
@molecule/lifecycle-decorator
000.0.24 years ago4 years agoMinified + gzip package size for @molecule/lifecycle-decorator in KB

Readme

MoleculeLifecycle

CircleCI Codecov npm (scoped)

The @MoleculeLifecycle-Decorator creates rxjs streams for all Angular and Ionic lifecycle hooks. Hooks will only be overridden when requesting their stream, in order to reduce unnecessary overhead.

@MoleculeLifecycle()
@Component({
  template: '{{latestDescription$|async}}'
})
export class YourComponent implements OnMoleculeLifecycle {
  @Input() description: Observable<string> | string;
  readonly latestDescription$: Observable<string>;
  readonly ngOnChanges$: Observable<SimpleChanges>;
  readonly ngOnDestroy$: Observable<void>;

  constructor() {
    this.latestDescription$ = this.ngOnChanges$.pluck('description', 'currentValue')
      .switchMap(newValue => {
        if (newValue instanceof Observable) {
          return <Observable<string>>newValue;
        } else {
          return Observable.of(newValue);
        }
      })
      .takeUntil(this.ngOnDestroy$)
      .subsrcibe();
  }
}

Installation

$ npm install --save @molecule/lifecycle-decorator

Author

Valentin Knabel, @vknabel, dev@vknabel.com

License

@molecule/lifecycle-decorator is available under the MIT license.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.