npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hookerjs

v0.2.1

Published

Hook Oriented Programming in JavaScript. Node.JS and the Browser

Downloads

6

Readme

hooker

Despite what the name suggests! This is a legitimate package for

Hook Oriented Programming in JavaScript. Node.JS and the Browser

This module brings hooks to the world of Client Side & Server Side JavaScript.

Installation

Node.js

npm install hooker

Browser

<script src = "hooker.min.js"> </script>

Usage

Basic Usage

Use hooker.register like subscribe, sub, on, etc.
Use hooker.trigger like publish, pub, emit, etc.

hooker.register('hooked', function (data) {
  console.log ('I am hooked to hooker', data);
});

hooker.register('hooked', function (data) {
  console.log ('I am also hooked to hooker', data);
});

hooker.trigger('hooked', {
  message: 'hooking up!'
});

//Outputs
'I am hooked to hooker', {message: 'hooking up!'}
'I am also hooked to hooker', {message: 'hooking up!'}

Data Passing

Each hook has some data passed to it. It can change this data for the next hook. All hooks have access to all the original data. Eg:

hooker.register('hooker', function (data, previousData) {
    console.log ('hooker1', data)
    console.log ('prevData', previousData);
    data.message = 'First!';
    return data;
})

//Outputs
'hooker1' {message: 'value'}
'prevData' [{message: 'value'}]



hooker.register('hooker', function (data, previousData) {
    console.log ('hooker2', data);
    console.log ('prevData', previousData);
    data.message = 'Second!';
    return data;
})

//Outputs
'hooker2' {message: 'First!'}
'prevData' [{message: 'value'}, {message: 'First!'}]



hooker.register('hooker', function (data, previousData) {
    console.log ('hooker3', data)
    console.log ('prevData', previousData);
    var myData = { message: 'Third!'}
    return myData;
})

//Outputs
'hooker3' {message: 'Second!'}
'prevData' [{message: 'value'}, {message: 'First!'}, {message: 'Second!'}]



var data = hooker.trigger('hooker', {
  'message': 'value'
});
console.log ('data', data);

//Outputs
'data' {
    final: {message: 'Third!'},
    previousData: [{message: 'value'}, {message: 'First!'}, {message: 'Second!'}]
}

API

Coming Soon

Technical details

How is this different than events?

In a traditional Pub Sub system, when an Event fires, all its listeners are fired simultaneously. Hooks are different because they are ordered. In the default configuration, hooks will be called one after another unless they are asynchronous.

Sequencing of Hooks

There will be an API later on for complete control over sequencing of when each listener will fire.

Performance

We hope to include a compiler which will inline most of the static hooking calls for much greater performance. Dynamic Hooks are a much more complex problem to solve and will be tackled in the issues.

Tests

We will include more tests using The Intern testing framework. For now you can just use test.js

Roadmap

  • [x] 0.1.0 Initial documentation and setup.
  • [x] 0.2.0 Basic synchronous hooks and simple API
  • [x] 0.2.1 Return Data.
  • [ ] 0.3.0 Integrate theintern with testcases and test infrastructure.
  • [ ] 0.4.0 Research on Asynchronous hooks and integration.
  • [ ] 0.5.0 Add performance tests and publish results.
  • [ ] 0.6.0 Public discussion and Community Involvement. ...
  • [ ] 1.0.0 Launch of first version for production.
  • [ ] 1.1.0 API to maintain order of hooks.

Contributing

Coming Soon. Till then, why don't you join the discussion?

Authors

Gaurav Ramanan

Copyright & License

(c) 2014 - 2015 RCorp. Code released under the Apache License.