Skip to content

Commit

Permalink
feat(client): Remove use of singleton pattern
Browse files Browse the repository at this point in the history
The singleton pattern has fallen out of favor lately, as it reduces the
flexibility of a module, and sometimes makes it harder to unit test.

More details on the singleton pattern: https://stackoverflow.com/questions/12755539/why-is-singleton-considered-an-anti-pattern

This change removes dbclient's use of the singleton pattern, which
should help folk who are using the module in ways we didn't anticipate.

Fixes #77
  • Loading branch information
orangejulius committed May 13, 2019
1 parent 61261bf commit 73d692d
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@

var elasticsearch = require('elasticsearch'),
settings = require('pelias-config').generate();

var singleton = null;
const elasticsearch = require('elasticsearch');
const settings = require('pelias-config').generate();

module.exports = function(){

// Create new esclient with settings
if( !singleton ){
singleton = new elasticsearch.Client( settings.esclient || {} );
}

return singleton;
return new elasticsearch.Client( settings.esclient || {} );
};

0 comments on commit 73d692d

Please sign in to comment.