@riyenz/method-hook-decorator
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Method Hook Decorator

Installation

This library is published in the NPM registry and can be installed using any compatible package manager.

npm install @riyenz/method-hook-decorator --save

# For Yarn, use the command below.
yarn add @riyenz/method-hook-decorator

The Old Way

@Component({
  ...
})
export class DefaultDashboardComponent implements OnInit {
  ngOnInit() {
    this._fetchData();
    this._setupDisplay();
  }

  private _fetchData() {
    ...
  }

  private _setupDisplay() {
    ...
  }
}

The Method Hook Way!

You can use method hook to have a clean and nicer looking code.

import { MethodHook } from '@riyenz/method-hook-decorator';

@Component({
  ...
})
export class DefaultDashboardComponent implements OnInit {
  ngOnInit() {
    ...
  }

  // calls _fetchData before ngOnInit
  @MethodHook.Before('ngOnInit')
  private _fetchData() {
    ...
  }

  // calls _setupDisplay after ngOnInit
  @MethodHook.After('ngOnInit')
  private _setupDisplay() {
    ...
  }
}

Documentation

Documentation generated from source files by Typedoc.

License

Released under MIT License.

Package Sidebar

Install

npm i @riyenz/method-hook-decorator

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

29.8 kB

Total Files

27

Last publish

Collaborators

  • riyenz