@molecule/lifecycle-decorator
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.2
    282
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.2
    282
  • 0.0.1
    2

Package Sidebar

Install

npm i @molecule/lifecycle-decorator

Weekly Downloads

16

Version

0.0.2

License

MIT

Last publish

Collaborators

  • vknabel