requarks / connect-loki

A Loki.js session store for Connect/Express

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code Optimization. Code Refactor.

Romick2005 opened this issue · comments

In connect-loki/lib/connect-loki.js:

  1. Promise = require('bluebird')//it is unused. It can be safely removed from code.
  2. You use only noop and isNill from loadash. But what is the reason to load hole loadash for this simple function and also add additional dependency? noop = function () {} and isNill = obj === null.
    So in package.json you can remove
"dependencies": {
    "bluebird": "^3.4.1",
    "lodash": "^4.15.0",
}
  1. What is the reason always pass to the function callpack functuion as a parameter? Like:
	LokiStore.prototype.clear = function (fn) {
		if(!fn) { fn = _.noop; }
		this.collection.clear();
		fn(null);
	};

I would make it more cleaner:

	LokiStore.prototype.clear = function () {
		return this.collection.clear();
	};

Because I guess "clear" method is synchronous and you don't need callback there.
So
lokiStore.clear(callback)
can be easily be rewritten to:

lokiStore.clear();
callback();

Update to v1.1.0. Unused dependencies were removed and code was refactored to StandardJS specs.

As for the callbacks, this is for compatibility reasons. Some apps expect to have a callback when calling a connect-style adapter. So even though everything is synchronous, I must provide the feature.