Browse Source

explicit .deps, ensure not published

Herbert Vojčík 7 years ago
parent
commit
4fd7d37e71
1 changed files with 10 additions and 10 deletions
  1. 10 10
      brikz.js

+ 10 - 10
brikz.js

@@ -17,8 +17,9 @@ function Brikz(api, apiKey, initKey) {
         return target;
     }
 
-    var d = {value: null, enumerable: false, configurable: true, writable: true};
-    Object.defineProperties(this, {ensure: d, rebuild: d});
+    Object.defineProperties(this, {
+        rebuild: {value: null, enumerable: false, configurable: true, writable: true}
+    });
     var exclude = mixin(this, {});
 
     this.rebuild = function () {
@@ -26,15 +27,18 @@ function Brikz(api, apiKey, initKey) {
             mixin(null, api, (backup[key] || 0)[apiKey] || {});
         });
         var oapi = mixin(api, {}), order = [], chk = {};
-        brikz.ensure = function (key) {
+
+        function ensure(key) {
             if (key in exclude) {
                 return null;
             }
             var b = brikz[key], bak = backup[key];
             mixin(null, api, api);
             while (typeof b === "function") {
+                (b.deps || []).forEach(ensure);
                 b = new b(brikz, api, bak);
             }
+            brikz[key] = b;
             if (b && !chk[key]) {
                 chk[key] = true;
                 order.push(b);
@@ -42,13 +46,9 @@ function Brikz(api, apiKey, initKey) {
             if (b && !b[apiKey]) {
                 b[apiKey] = mixin(api, {});
             }
-            brikz[key] = b;
-            return b;
-        };
-        Object.keys(brikz).forEach(function (key) {
-            brikz.ensure(key);
-        });
-        brikz.ensure = null;
+        }
+
+        Object.keys(brikz).forEach(ensure);
         mixin(oapi, mixin(null, api, api));
         order.forEach(function (brik) {
             mixin(brik[apiKey] || {}, api);