[patch request] API object is empty in components
ro0p opened this issue · 2 comments
You example usage simply doesnt work for me, because "import API from './Api';" in components forces to create a new empty API object, so all storage definitions are lost.
Maybe I missed something, or trying to use your lib in a wrong way, but I cannot find out how the API object can be used as a global interface.
I can solved it with using singleton pattern for APIsHolder object. Here is the patch:
--- ./createAPIsHolder.orig.js 2016-09-29 17:17:55.000000000 +0200
+++ ./createAPIsHolder.js 2016-12-04 03:24:08.712551108 +0100
@@ -8,6 +8,7 @@
var _utils = require('./utils');
function createAPIsHolder() {
+ var _instance;
function APIsHolder() {}
function addAPIActions(apiName, actions) {
@@ -23,5 +24,7 @@
``
APIsHolder.prototype.addAPIActions = addAPIActions;
- return new APIsHolder();
-}
+ if (!_instance)
+ _instance = new APIsHolder();
+ return _instance;
+}
Thank you for this great lib!