var fs = require('fs'); var Promise = require('bluebird'); var _ = require('lodash'); var Middleware = require('./middleware'); var helpers = require('../util/helpers'); /** * The Cors Middleware. * */ var Cors = module.exports = {}; /** * CORS Middleware * * @param {Object} req The request Object. * @param {Object} res The response Object. * @param {Function(Error=)} next pass ctrl. */ Cors.use = function(req, res, next) { ... }; Module Description Dependencies System Deps NPM Deps Project Deps Export Statement Method Definition DocBlocks for Args Function Expression
--> Ctor Helpers / Util --> Obj Enums / Dicts --> Obj Config Files --> Obj When to use which When to use which It's all about the state It's all about the state
Pattern at its Best var util = require('util'); var EventEmitter = require('events').EventEmitter; var MiddlewareBase = module.exports = function() { EventEmitter.apply(this, arguments); this.foo = 1; }; util.inherits(MiddlewareBase, EventEmitter); Base Constructors vanilla var EventEmitter = require('events').EventEmitter; var cip = require('cip'); var CeventEmitter = cip.cast(EventEmitter); module.exports = CeventEmitter.extend(); Base Constructors using CIP
Pattern at its Best var util = require('util'); var MiddleWareBase = require('./middleware-base.midd'); var Cors = module.exports = function() { MiddlewareBase.apply(this, arguments); console.log(this.foo); // 1 }; util.inherits(Cors, MiddlewareBase); Child Constructors vanilla var MiddlewareBase = require('./middleware-base.midd'); var Cors = module.exports = MiddlewareBase.extend(function () { /* Ctor */ }); Child Constructors using CIP
Pattern at its Best var MiddlewareBase = require('./middleware-base.midd'); var MiddlewareTraits = require('./middleware-traits.midd'); var Cors = module.exports = MiddlewareBase.extend(function () { /* Ctor */ }); Cors.mixin(MiddlewareTraits); Mixins! var Cors = require('./cors.midd'); var SuperCors = module.exports = Cors.extend(function () { /* Ctor */ }); Inheritance Goes on...