Fast, tiny and solid hooks system for Javascript and Node.js

Overview

Uncino 🪝

Fast, tiny and solid hooks system for Javascript and NodeJS

Uncino is italian word for hook

Uncino - Fast, tiny and solid hooks system for Javascript and NodeJS

Do you know Wordpress hooks system? Uncino is a hooks system highly inspired to it!

  • Async / Await support
  • Node or Browser support
  • Actions / Hooks system
  • Easy to use
  • No Dependencies

Support this project

Buy me a coffee

Installation

npm i uncino or yarn add uncino

Quick example

const uncino = require('uncino')
const hooks = uncino()

hooks.addHook('test', 'namespace', async (number) => {
  return number + 10
})

hooks.addHook('test', 'namespace', async (number) => {
  return number + 20
})

async function testHook(myNumber) {
  const newNumber = await hooks.runHook('test', myNumber)
  console.log(myNumber, newNumber)
}

testHook(3)  // 3 33
testHook(10)  // 10 40

Philosophy

Uncino permit to your code to interact/modify another piece of code at specific, pre-defined spots.

Uncino has two types of hooks: Actions and Hooks. To use either, you need to write a custom function, and then register for a specific action or hook.

Actions allow you to add data or change how your code operates. Actions will run at a specific point in the execution. Callback functions for Actions can perform some kind of a task, like echoing output to the user or inserting something into the database. Callback functions for an Action do not return anything back to the calling Action hook.

Hooks give you the ability to change data during the execution of your code. Callback functions for Hooks will accept a variable, modify it, and return it. They are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output. Hooks expect to have something returned back to them.

With Uncino you can create your own hook spots so that other developers can extend and modify your code or you can create your pluggable core.

Hooks API

Method Name Arguments Description
addHook hookName, namespace, callback, priority Register callback as new hook for hookName in namespace with priority (default: 10).
removeHook hookName, namespace Remove hook for hookName in namespace
hasHook hookName, namespace Check if hook for hookName in namespace exists
removeAllHooks hookName Remove all hooks for hookName
runHook hookName, params Run hook for hookName with params. It returns a Promise with the hook result

Actions API

Method Name Arguments Description
addAction actionName, namespace, callback, priority Register callback as new action for actionName in namespace with priority (default: 10).
removeAction actionName, namespace Remove hook for actionName in namespace
hasAction actionName, namespace Check if hook for actionName in namespace exists
removeAllActions actionName Remove all actionss for actionName
runAction actionName, params Run action for actionName with params. It returns a Promise with void value

Example

Clone the repo and look in the test folder

Develop

Clone the repo then use npm install for download all the dependencies then launch npm run build for build the project

Pull Requests?

I'd love them!

Comments?

Let's hear them! (The nice ones please!)

Me?

In case you're interested I'm @riktarweb

You might also like...

React Hooks library for remote data fetching

React Hooks library for remote data fetching

Introduction swr.vercel.app SWR is a React Hooks library for remote data fetching. The name “SWR” is derived from stale-while-revalidate, a cache inva

Jan 4, 2023

Redux-Toolkit example with React Hooks CRUD Application, Axios, Rest API, Bootstrap

Redux-Toolkit example with React Hooks CRUD Application, Axios, Rest API, Bootstrap

Redux-Toolkit CRUD example with React Hooks, Axios & Web API Build Redux-Toolkit CRUD application with React Hooks and Rest API calls in that: Each it

Dec 27, 2022

React Hooks tutorial for beginners.

React Hooks for Beginners git clone url Clone into the repo code react-hooks Open the folder in VS Code npm install Install the dependencies npm sta

Oct 10, 2022

A custom ESLint rule to allow static deps in React Hooks ⚛️

eslint-plugin-react-hooks-static-deps A custom ESLint rule to allow static deps in React Hooks ⚛️ Motivation react-hooks/exhaustive-deps is a really n

Apr 5, 2022

A library of RxJS-related hooks

rxooks GADZOOKS! RXOOKS! (Basically every other iteration of "rxjs", "rx", "react", and "hooks" was taken) This is a library of hooks that are useful

Nov 28, 2022

A tiny package for JavaScript Web App's state management based on RxJS & Immer

A tiny package for JavaScript Web App's state management based on RxJS & Immer

Oct 19, 2022

Tiny and powerful state management library.

Tiny and powerful state management library.

BitAboutState Tiny and powerful React state management library. 100% Idiomatic React. Install npm install --save @bit-about/state Features 100% Idioma

Nov 5, 2022

Super tiny color input ranges for React.

Super tiny color input ranges for React.

react-color-range · Tiny color input for React, made with native input ranges. react-color-range leverages the native input type="range" and CSS linea

Jan 16, 2022

🔮 tiny robust state management

🔮 snapstate tiny robust state management 📦 npm install @chasemoskal/snapstate 👁️ watch for changes to properties 🕵️ track only the properties you

Dec 23, 2022
Comments
  • Write better tests for the library

    Write better tests for the library

    Currently the tests included only check for quite trivial behaviours but don't really guarantee the correctness of the original code in various aspects.

    Additional tests are needed to check:

    • The functions passed as hooks are what is actually being called when running the hook. This should involve creating some mock or stub functions and then checking that they have been called with some assertion. As they currently are written most tests would pass even if runHook simply returned the passed argument plus 3 ignoring everything else.
    • That actions actually run. Currently the tests only verify that actions are stored and that runAction resolves but they don't check anything at all about the actions actually being executed. Again, some mocks should be setup and used to verify that they have actually been called.
    • That the "priority" argument works. Currently there's no test at all that verifies in any way the order/priority in which the functions are called. This applies to both hooks and actions.
    • A number of additional edge cases. It would be useful to have tests that check things like calling runHook with no hooks added, or calling removeHook when no hook has been added, or removing/adding hooks from inside a hook function (what is the expected behaviour here? is it documented anywhere?), or some other similar infrequent but not unthinkable cases.

    Note that all these things are probably correct in the code now. I'm not saying there are any errors right now, but I'm also not saying that there aren't. What I'm saying is that the included tests are too weak to be useful for anything; they offer very little or no safety at all.

    opened by gezeta-id 1
Releases(1.0.0)
Owner
Riccardo Tartaglia
Full Stack Developer at @webeetle - Make stuff on the web
Riccardo Tartaglia
Drop-in replacements for @apollo/client's useQuery, useMutation and useSubscription hooks with reduced overhead and additional functionality.

apollo-augmented-hooks Drop-in replacements for @apollo/client's useQuery, useMutation and useSubscription hooks with reduced overhead and additional

appmotion Devs 57 Nov 18, 2022
⚛️ Hooks for fetching, caching and updating asynchronous data in React

Hooks for fetching, caching and updating asynchronous data in React Enjoy this library? Try the entire TanStack! React Table, React Form, React Charts

Tanner Linsley 32.1k Jan 9, 2023
Fully typed hooks and utility functions for the React Native StyleSheet API

react-native-style-utilities Fully typed hooks and utility functions for the React Native StyleSheet API npm i react-native-style-utilities ESLint Set

Marc Rousavy 73 Dec 17, 2022
Built a covid-19 trcaker app using React.js implementing hooks and materail UI

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Aditya Dond 1 Dec 21, 2021
Add multiplayer presence (live cursors/avatars) to your react application using yjs and hooks

y-presence Easy way to add presence (live cursors/avatars) to any react application using react hooks. Installation yarn add y-presence # or npm i y-p

Nimesh Nayaju 126 Dec 29, 2022
preact.js with hooks and ES2021, without compilers

naked preact preact.js with hooks, without compilers Web development should be simple. No compilers, just ES2021 and preact+hooks. See comments in the

Oleksandr Nikitin 3 Jun 16, 2022
React components and hooks for creating VR/AR applications with @react-three/fiber

@react-three/xr React components and hooks for creating VR/AR applications with @react-three/fiber npm install @react-three/xr These demos are real,

Poimandres 1.4k Jan 4, 2023
A npm package to increase the developer experience and consistency by providing a set of hooks that can be opted-in the development lifecycle.

@jeliasson/husky-hooks This npm package aims to increase the developer experience and consistency by providing a set of hooks that can be opted-in the

Johan Eliasson 8 Dec 6, 2022
React Hooks — 👍

Collaborative editing for your app. Support on Kickstarter! ?? react-use Collection of essential React Hooks. Port of libreact. Translations: ???? 汉语

Vadim Dalecky 34.9k Jan 3, 2023
📋 React Hooks for forms validation (Web + React Native)

English | 繁中 | 简中 | 日本語 | 한국어 | Français | Italiano | Português | Español | Русский | Deutsch | Türkçe Features Built with performance and DX in mind

React Hook Form 32.4k Dec 29, 2022