1.0.1 • Published 5 years ago

@riyenz/method-hook-decorator v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

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.