fdz-hook

A simple way to add hooks in any javascript aplication - Vanilla JS


Keywords
hook, plugin, fdz-hook, library
License
MIT
Install
npm install fdz-hook@2.0.1

Documentation

FDZ Hooks

A simple way to add hooks in any javascript aplication - Vanilla JS

Browser Support

This library relies on Map API. And this API is supported in the following browsers.

Chrome Firefox Opera Safari IE
49+ ✔ 54+ ✔ 47+ ✔ 10.1+ ✔ 11 ✔

Dependencies

This library is totally make in Vanilla JS

Installation

$ npm install fdz-hook --save

How to use

ES6

// to import a specific method
import Hook from 'fdz-hook';

const hook = new Hook();

// using  method
hook.register('click', () => console.log('Works!'));

CommonJS

const Hook = require('fdz-hook');

const hook = new Hook();

UMD in Browser

<!-- to import non-minified version -->
<script src="fdz-hook.umd.js"></script>

<!-- to import minified version -->
<script src="fdz-hook.umd.min.js"></script>

After that the library will be available to the Global as Hook. Follow an example:

const hook = new Hook();

hook.register('beforeOpen', () => {
  console.log('Opening!');
});

Methods

Follow the methods that the library provides.

hook.register(name, fn)

Register a hook inside hook object

Arguments

Argument Type Options
name string 'inform a hook name'
fn function 'provide a callback'

Example

hook.register('beforeMount', (instance) => {
  // do something
});

hook.call(name, args1, args2...)

Call a hook from hook object

Arguments

Argument Type Options
name string 'inform a hook name'
args any 'provide arguments one by one'

Example

hook.call('beforeMount', { name: 'Lorem' });

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

Daniel Simão
Daniel Simão

See also the list of colaborators who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details