Hunk.js
Micro-framework for JavaScript applications modularization, for Node.js and the browser.
Hunk is not a package manager. Hunk has been created to promote better JS factorisation, and to help modularize little — and eventually big — web applications.
Benefits
- Really tiny
- Promote better code factorisation
- Fun!
- Huge doc for less than 150 lines of codes
Install
npm install --save hunky
Soon available on bower.
Basics
A first module
Let's create an hello world module!
// Let's get started!// First we create our module container, that is self called// Here we see an `hello` parameter. We'll speak about it very soon. For now,// you should only understand that this parameter is your module' public // methods container.{ // So let's define our first method // We register it in our public container with the name `speak` hello { ; }; // Here is the trick: that's where we pass our public container parameter, // generated by hunk. Hunk will kindly generate the container for us, and // pass it to our main function.};
Great! We have a module! Now how to call it? By calling hunk('hello')
again:
var hello = hunk('hello');
hello.speak();
// -> Hello world!
Perfect! You did it!
For your information, the module you just created was a static module - one that can't be instanciated.
Start and stop Hunk
Sometimes, particularly in the browser while the DOM is loading, but also in Node when stuff has to be initialized before the app can start, you need to defer the startup of your application at a time of your choice. If you need that, then you can use Hunk start/stop signals.
Include the Hunk JS source, then just call hunk()
that will start or stop
modules depending on current state.
Core modules
Hunk embeds a few core modules that can be really useful to speed up JS apps development.
Conf
conf
core module is a tiny static module to manage a key/value pairs centralized
storage.
{ 'use strict'; var conf = hunkconf; self { ; }; self { console; // "value" }; }; // Start, will set conf `key` > `Hello Hunk`; // Stop;// -> "Hello Hunk"
Hunk API
hunk()
Main hunk method has many use, depending on the kind of parameters we pass to it:
hunk()
- without parameter - Will start/stop hunk app
Get hunk running status
To know whether hunk is running or not, one may use hunk.state
method.
Call a function when hunk starts
// Add a start hook; // ... later on, start hunk;// -> "App just started!"
Changelog
1.0.1
- Fix for Node.js
1.0.0
- Initial version, with core conf module and working triggers.
Work on the project
Build hunk for the browser
For Node.js it is unnecessary to build hunk. However, you may want to lint it, check it with Google Closure Compiler, or for the browser you may want a minified version of hunk (the one in dist/
folder).
Be happy, the default gulp task will cover everything:
gulp