Skip to content

Commit

Permalink
perf: remove argument reassignment
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jun 24, 2016
1 parent 9d21d90 commit d95275b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ unreleased
- Use `random-bytes` for byte source
- deps: [email protected]
* perf: enable strict mode
* perf: remove argument reassignment

1.13.0 / 2016-01-10
===================
Expand Down
50 changes: 33 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,35 @@ var defer = typeof setImmediate === 'function'
* @public
*/

function session(options){
var options = options || {}
// name - previously "options.key"
, name = options.name || options.key || 'connect.sid'
, store = options.store || new MemoryStore
, trustProxy = options.proxy
, storeReady = true
, rollingSessions = options.rolling || false;
var cookieOptions = options.cookie || {};
var resaveSession = options.resave;
var saveUninitializedSession = options.saveUninitialized;
var secret = options.secret;

var generateId = options.genid || generateSessionId;
function session(options) {
var opts = options || {}

// get the cookie options
var cookieOptions = opts.cookie || {}

// get the session id generate function
var generateId = opts.genid || generateSessionId

// get the session cookie name
var name = opts.name || opts.key || 'connect.sid'

// get the session store
var store = opts.store || new MemoryStore()

// get the trust proxy setting
var trustProxy = opts.proxy

// get the resave session option
var resaveSession = opts.resave;

// get the rolling session option
var rollingSessions = Boolean(opts.rolling)

// get the save uninitialized session option
var saveUninitializedSession = opts.saveUninitialized

// get the cookie signing secret
var secret = opts.secret

if (typeof generateId !== 'function') {
throw new TypeError('genid option must be a function');
Expand All @@ -112,12 +127,12 @@ function session(options){
saveUninitializedSession = true;
}

if (options.unset && options.unset !== 'destroy' && options.unset !== 'keep') {
if (opts.unset && opts.unset !== 'destroy' && opts.unset !== 'keep') {
throw new TypeError('unset option must be "destroy" or "keep"');
}

// TODO: switch to "destroy" on next major
var unsetDestroy = options.unset === 'destroy';
var unsetDestroy = opts.unset === 'destroy'

if (Array.isArray(secret) && secret.length === 0) {
throw new TypeError('secret option array must contain one or more strings');
Expand Down Expand Up @@ -151,7 +166,8 @@ function session(options){

var storeImplementsTouch = typeof store.touch === 'function';

// register event listeners for the store
// register event listeners for the store to track readiness
var storeReady = true
store.on('disconnect', function ondisconnect() {
storeReady = false
})
Expand Down
3 changes: 1 addition & 2 deletions session/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ Store.prototype.load = function(sid, fn){
if (err) return fn(err);
if (!sess) return fn();
var req = { sessionID: sid, sessionStore: self };
sess = self.createSession(req, sess);
fn(null, sess);
fn(null, self.createSession(req, sess))
});
};

Expand Down

0 comments on commit d95275b

Please sign in to comment.