moshen / node-googlemaps

A simple way to query the Google Maps API from Node.js
MIT License
560 stars 148 forks source link

semi-singleton architecture should be reviewed #51

Closed fabriziomoscon closed 9 years ago

fabriziomoscon commented 10 years ago

Since the library doesn't export a constructor the _config object is global for all the calls you make within the same running process. This prevent the execution of multiple API calls that requires different configuration keys. For example running a simple geocoding as Business user will set google-client-id and google-private-key globally also for calls to the place API that don't need them.

Because of the way require works in node http://nodejs.org/api/modules.html#modules_caching I cannot use 2 library in my code as a workaround.

Exporting a constructor would allow users to have multiple objects which don't share _config

moshen commented 10 years ago

:+1:

fabriziomoscon commented 10 years ago

I leave this here as a reference: http://fredkschott.com/post/2014/01/node-js-cookbook---constructors-and-custom-types/

this work has started: https://github.com/moshen/node-googlemaps/tree/new-major-version

fabriziomoscon commented 9 years ago

PR #70 addresses this issue