hapi icon indicating copy to clipboard operation
hapi copied to clipboard

Question: should pack.register's register pack parameter should be renamed to plugin?

Open paullang opened this issue 13 years ago • 1 comments

In the API Reference http://spumko.github.io/resource/api/#pack-register-plugin--options--callback- and all the integration tests for pack.register https://github.com/spumko/hapi/blob/master/test/integration/pack.js, all the code uses pack as the first parameter name to the plugin's register method, but should this be plugin instead?

If you call console.dir(pack), you will see it has all the methods and properties from the plugin interface and is not a pack. I understand this is just a parameter name, but naming it plugin would make it clearer what type of object it is.

Renaming it would also make it consistent with pack.require.

e.g.

Current

var plugin = {
    name: 'test',
    version: '2.0.0',
    register: function (pack, options, next) {

        pack.route({ method: 'GET', path: '/special', handler: function () { this.reply(options.message); } } );
        next();
    }
};

Proposed

var localPlugin = {
    name: 'test',
    version: '2.0.0',
    register: function (plugin, options, next) {

        plugin.route({ method: 'GET', path: '/special', handler: function () { this.reply(options.message); } } );
        next();
    }
};

paullang avatar Jul 14 '13 04:07 paullang

It used to be called pack but was changed in 1.0. Can you PR to correct all the errors in the examples/tests/docs you spotted?

Instead of localPlugin, just use plug or something short.

hueniverse avatar Jul 14 '13 07:07 hueniverse