Coder Social home page Coder Social logo

hook-by-priority's Introduction

hook-by-priority

Hooking system using priority numbers.

Advantages

  • Asynchronous hooks.
  • Parameters passed along the cycle of hooks.
  • Less than 50 lines of code.
  • For node.js or browser.
  • No dependencies at all.

Installation

$ npm install -s hook-by-priority

Usage

This example appends a character for each hook asynchronously.

It also uses priority option to order the hooks added to the created hooks-manager.

const Hooks = require("hook-by-priority");
const hooks = Hooks.create();

const add = function(char, data) {
	return new Promise(function(ok, fail) {
		data.msg += char;
		setTimeout(ok, 100);
	});
};

hooks.add("on:init", async params => await add("e", params), 90);
hooks.add("on:init", async params => await add("!", params), 50);
hooks.add("on:init", async params => await add("l", params), 70);
hooks.add("on:init", async params => await add("o", params), 60);
hooks.add("on:init", async params => await add("l", params), 80);
hooks.add("on:init", async params => await add("H", params), 100);
hooks.use("on:init", { msg: "" }).then(output => console.log(output.msg));

This script is also under test/readme.test.js file of the project.

License

This project is released under WTFPL (or What The Fuck Public License), which means do what you want.

Issues

Please, address your issues here.

hook-by-priority's People

Contributors

allnulled avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.