AmpersandJS / examples

A collection of example apps/patterns using ampersand
MIT License
45 stars 16 forks source link

What's the purpose of the internals object? #9

Closed minustime closed 9 years ago

minustime commented 9 years ago

Thanks for sharing these patterns. I've seen the internals object in a few hapijs projects. Is the internals object's purpose just to encapsulate application level code?

fyockm commented 9 years ago

To my understanding, internals is a way to use client cookies to persist a state across multiple requests. For more info, see http://hapijs.com/api#serverstatename-options

geek commented 9 years ago

@minustime are you referring to this coding style: https://github.com/hapijs/hapi/blob/master/lib/auth.js#L8-L10 ???

minustime commented 9 years ago

Hey @geek yup, I saw it in the hapi.js code first, then on some plugins and now here https://github.com/AmpersandJS/examples/blob/master/hapi-hbs/server.js#L8 so I was curious of the significance of the object.

geek commented 9 years ago

@minustime our style guide talks about it here: http://hapijs.com/styleguide#user-content-module-globals

Its actually really handy when you get used to it, makes it easier to identify any scope leaks in a module. But I prefer it for this line when declaring a constructor:

module.exports = internals.Server = function (options) {

Compare that to this style

var Server = function () {
...
};

module.exports = Server;

Keep in mind that we also avoid hoisted functions.

minustime commented 9 years ago

Got it. I don't think I came across that style guide before, thanks for the explanation and the link.

fyockm commented 9 years ago

@geek thanks for jumping in to explain.