fdz-hook
v2.0.1
Published
A simple way to add hooks in any javascript aplication - Vanilla JS
Downloads
3
Readme
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.
| | | | | --- | --- | --- | --- | --- | 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 |
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