From 8fe8355809d0acb9cc4d0d1e9db93b82ec180e9b Mon Sep 17 00:00:00 2001 From: David Worms Date: Sat, 3 Aug 2024 09:22:29 +0200 Subject: [PATCH] docs: update doc links --- README.md | 62 +++++++++++++++++++++++------------------------ docs/5.handler.md | 4 +-- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index bdd1159..d81d803 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,20 @@ - [![Build Status](https://secure.travis-ci.org/adaltas/node-plug-and-play.svg)](http://travis-ci.org/adaltas/node-plug-and-play) # Node.js Plug-And-Play package Easily create hooks and let users plug their own logic across your code to make it extensible by everyone with new features. -## Main features +## Main features -* Extention points definition +- Extention points definition Simple to declare new extention points, yet a lot of flexibility to the plugin authors. -* Hook definition +- Hook definition Plugin writer can intercept calls to a function by placing their own logicl before, after and even switching the default implementation. -* Dependency management +- Dependency management Plugins can require other plugins as required dependencies as well as choose the order of execution of each hook. -* Promise support +- Promise support Hook can be synchronous and asynchronous when returning a promise. -* Nested/hierachical +- Nested/hierachical Instanciate plugin instances with a parent reference and parent hooks will also be available inside the children. ## Learning @@ -28,62 +27,63 @@ Here is the documentation: - [Initialize a new instance](./docs/2.initialization.md) - [Plugins registration](./docs/3.plugins.md) - [Hook declaration](./docs/4.hook.md) -- [API usage](./docs/5.api.md) -- [Developers instructions](./docs/6.developers.md) +- [Hook handler definition and usage](./docs/5.handler.md) +- [API usage](./docs/6.api.md) +- [Developers instructions](./docs/7.developers.md) ## Quick example Library and application authors define hooks, see [`./sample/lib.js`](https://github.com/adaltas/node-plug-and-play/blob/master/sample/lib.js): ```js -const plugandplay = require('plug-and-play') +const plugandplay = require("plug-and-play"); -const plugins = plugandplay() +const plugins = plugandplay(); module.exports = { // Create and export a new Plug and Play instance plugins: plugins, // Our core library function - print: function() { + print: function () { // Wrap-up code plugins.call({ // Identify this hook with a name - name: 'hooks:print', + name: "hooks:print", // Expose arguments to plugins authors args: { - data: { message: 'hello' } + data: { message: "hello" }, }, // Default implementation - handler: ({data}) => { + handler: ({ data }) => { // Original library - console.log(data.message) - } - }) - } -} + console.log(data.message); + }, + }); + }, +}; ``` Users and pluging authors can now register their own hooks, see [`./sample/index.js`](https://github.com/adaltas/node-plug-and-play/blob/master/sample/error.js): ```js -const mysuperlibrary = require('./lib') +const mysuperlibrary = require("./lib"); mysuperlibrary.plugins.register({ hooks: { - 'hooks:print': ({data}, handler) => { + "hooks:print": ({ data }, handler) => { // Alter the argument - data.message = 'Hello World' + data.message = "Hello World"; // Print a message before the library code - console.log('>>>>>>>>>>>') + console.log(">>>>>>>>>>>"); // Call the original handler - const result = handler.call(null, {data: data}) + const result = handler.call(null, { data: data }); // Print a message after the library code - console.log('<<<<<<<<<<<') - return result - } - } -}) -mysuperlibrary.print() + console.log("<<<<<<<<<<<"); + return result; + }, + }, +}); +mysuperlibrary.print(); ``` While the original `print` function was only printing `Hello` to stdout, the introduction of this new plugin prints: diff --git a/docs/5.handler.md b/docs/5.handler.md index feed32f..0743b04 100644 --- a/docs/5.handler.md +++ b/docs/5.handler.md @@ -1,6 +1,6 @@ -# Hook handler definition and pattern usage +# Hook handler definition and usage -The hook handler alter the behavior of original handler passed by `call` or `call_sync`. Its implementation allos multiple execution pattern: +The hook handler alter the behavior of original handler passed by `call` or `call_sync`. Its implementation allos multiple execution patterns: - Execute code before and after the original handler - Alter the arguments arguments