hin.js
v1.0.24
Published
### Target Feature Set - *Strong* typings using vanilla JS - Granular, additive *inheritance*, avoiding the fragile base class problem - Easy, flexible, granular *dependency injection* - *Precise refactoring* within IDEs
Downloads
416
Readme
hin.js
Target Feature Set
- Strong typings using vanilla JS
- Granular, additive inheritance, avoiding the fragile base class problem
- Easy, flexible, granular dependency injection
- Precise refactoring within IDEs
The most wonderful feature of hin.js is the dependency injection.
Composable classes, singletons become easy to structure and easy to swap. That is in part thanks to inheritance that is far more granular than traditional: in hin.js each class property has its own inheritance.
It really shines when you need to take a prototype to production quality software seamlessly.
Docs are active work-in-progress!
Contents
Stateful vs Stateless Hinjs
Grouping
Injection
Public dependencies
Private dependencies
Singletons
Mocking dependencies
A small example to give you a sense of how small the interface surface is and how easy hin.js is
import {hinj, group} from 'hin.js'
const Database = group({
connectionUrl: hinj(process.env.CONNECTION_URL),
sql: hinj(
/* setting lazy, default value */
T => {
const url = Database.connectUrl(T)
// if using postgres library
return postgres(url)
}),
})
const Server = group({
$handleIndex: hinj()
.async(await (T, {req, res}) => {
const i = Index(T) // creating a new instance of Index
// and setting this instnace of Server as the parent
await Index.$load(i)
const list = Index.list(i)
const html = list.length ?
`<ul>${list.map(r => `<li>${r}</li>`)}</ul>`
: '<b>Nothing found!</b>'
res.end(html)
})
})
const Index = group({
list: hinj(),
$load: hinj()
.async(await T => {
const sql = Database.sql(T) // dependency injection at work
const list = await sql`SELECT path FROM files`
Index.list(T, list.map(r => r.path))
})
})
// Initializing
const db = Database()
const server = Server(db) // Database becomes the parent of Server
// Now all hinj functions in Server have access to `db`
// through dependency injection
// Running
Server.$handleIndex(server, {/* req, res from Express.js */})
Hinges (stylized hin.js) is the result of a lineage of work:
- Layer-compose: the grandmother of the lineage, which tried to do too much
- Filo: that got it almost right
- Hinges: is the stripped down version of Filo that gives granular control while giving better coding ergonomics.
hin.js is a stable set of procedures, commands and library interface. It satisfies the target feature set already, the interface does not need to change.
There might be a few ergonomic improvements introduced on the way to 2.0.0 (which will take a long time). Those would be inconsequential and backwards compatible.
The additional functionality (because who doesn't like to have it their way?) will come as plugins.