Honk
Honk, pronounced "
"Honk", because, by default, that is all that it does.
Package | Version |
---|---|
@honkjs/honk | |
@honkjs/injector | |
@honkjs/store | |
@honkjs/silence |
Getting started
npm install @honkjs/honk
import Honk from '@honkjs/honk';
const honk = new Honk().honk;
honk(); // output: "🚚 HONK!"
With service injection (thunks)
import Honk from '@honkjs/honk';
import injector from '@honkjs/injector';
const honk = new Honk().use(injector()).honk;
honk(); // output: "🚚 HONK!"
function delayedHonk(delay: number) {
return function({ honk }: IHonkServices) {
setTimeout(() => honk(), delay);
};
}
honk(delayedHonk(1000)); // output after 1000ms: "🚚 HONK!"
With custom services
import Honk from '@honkjs/honk';
import injector from '@honkjs/injector';
const honk = new Honk()
.use(injector({ time: 100 }))
.honk;
honk(); // output: "🚚 HONK!"
function honkOne({ honk, time }) {
setTimeout(() => honk(), time);
}
honk(honkOne); // output after 100ms: "🚚 HONK!"
With custom middleware
import Honk from '@honkjs/honk';
function honkingMiddleware(app, next) {
return function(args) {
if (args.length === 1 && args[0].type) {
const honkType = args[0].type;
if (honkType === 'quiet') {
return '🚚 HONK!';
} else {
return '🚚 HONK!';
}
}
return next(args);
};
}
const honk = new Honk().use(honkingMiddleware).honk;
honk(); // output: "🚚 HONK!"
const quiet = honk.honk({ type: 'quiet' }); // output: nothing.
// quiet = "🚚 HONK!"
const loud = honk.honk({ type: 'loud' }); // output: nothing.
// loud = "🚚 HONK!"
With silence
import Honk from '@honkjs/honk';
import silence from '@honkjs/silence';
const honk = new Honk().use(silence()).honk;
honk(); // output: Nothing. Just the silence of your cold, dead heart.