Code Optimization. Code Refactor.
Romick2005 opened this issue · comments
Romick2005 commented
In connect-loki/lib/connect-loki.js:
Promise = require('bluebird')
//it is unused. It can be safely removed from code.- 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",
}
- 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();
Nicolas Giard commented
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.