{"repo":"gr2m/before-after-hook","free":true,"listed":false,"github":"https://github.com/gr2m/before-after-hook","clone":"git clone https://github.com/gr2m/before-after-hook.git","description":"wrap methods with before/after hooks","language":"JavaScript","stars":83,"topics":["promise","hooks","api","async","events","asynchronous"],"license":"Apache-2.0","category":"api-integrations-sdks","readme_excerpt":"before-after-hook asynchronous hooks for internal functionality Usage Browsers Load before-after-hook directly from cdn.skypack.dev Node Install with npm install before-after-hook Singular hook Hook collection Hook.Singular vs Hook.Collection There's no fundamental difference between the Hook.Singular and Hook.Collection hooks except for the fact that a hook from a collection requires you to pass along the name. Therefore the following explanation applies to both code snippets as described above. The methods are executed in the following order 1. beforeHook 2. fetchFromDatabase 3. afterHook 4. handleData beforeHook can mutate options before it’s passed to fetchFromDatabase . If an error is thrown in beforeHook or fetchFromDatabase then errorHook is called next. If afterHook throws an error then handleGetError is called instead of handleData . If errorHook throws an error then handleGetError is called next, otherwise afterHook and handleData . You can also use hook.wrap to achieve the same thing as shown above (collection example): API - Singular Hook Constructor - Hook Collection Constructor Singular hook API - Singular constructor - hook.api - hook() - hook.before() - hook.error() - hook.after() - hook.wrap() - hook.remove() Singular constructor The Hook.Singular constructor has no options and returns a hook instance with the methods below: Using the singular hook is recommended for TypeScript Singular API The singular hook is a reference to a single hook. This means that th","default_branch":null,"files":null,"tree":[],"storefront":"/r/gr2m","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/gr2m/before-after-hook/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}