@dualbox/editor 1.0.40 → 1.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -206,7 +206,23 @@ class DualboxEditor {
206
206
 
207
207
  this.loadCorePackages();
208
208
 
209
+ // if defined, call progress callback when needed
210
+ // signature: onLoadProgress(stepName, percentage);
211
+ this.onLoadProgress = attrs.onLoadProgress || function (stepName, numberDone, numberTotal) {
212
+ if (numberDone && numberTotal) {
213
+ console.log(`[LOAD] ${stepName}: ${numberDone}/${numberTotal}`);
214
+ } else {
215
+ console.log(`[LOAD] ${stepName}`);
216
+ }
217
+ };
218
+
209
219
  if (attrs.json) {
220
+ this.onLoadProgress((step, nbDone, nbTotal) => {
221
+ if (attrs.onLoadProgress) {
222
+ p.onLoadProgress(step, nbDone, nbTotal);
223
+ }
224
+ });
225
+
210
226
  this.onReady(() => {
211
227
  var p = this.setApp(attrs.json);
212
228
  if (attrs.onLoaded) {
@@ -228,10 +244,10 @@ class DualboxEditor {
228
244
 
229
245
  var pkgName = "@dualbox/dualbox";
230
246
  await this.loadPackage(pkgName);
231
- if (!window.DualBox && window.DualBox.start) {
232
- this.DualBox = window.DualBox = this.require(pkgName);
233
- } else {
247
+ if (window.DualBox && window.DualBox.start) {
234
248
  this.DualBox = window.DualBox;
249
+ } else {
250
+ this.DualBox = window.DualBox = this.require(pkgName);
235
251
  }
236
252
  _.each(this.DualBox.core, async corePackage => {
237
253
  await this.loadPackage(corePackage.name);
@@ -250,11 +266,18 @@ class DualboxEditor {
250
266
  // return a Promise
251
267
  loadPackages(json) {
252
268
  var promises = []; // array of promises
253
- this.promises = promises;
269
+ this.promises = [];
270
+
271
+ var nbPackages = 0;
272
+ var nbLoaded = 0;
254
273
 
255
274
  var parser = new AppParser(json);
256
275
  parser.eachComponent((name, version) => {
257
- promises.push(this.loadPackage(name, version));
276
+ nbPackages++;
277
+ promises.push(this.loadPackage(name, version).then(() => {
278
+ nbLoaded++;
279
+ this.onLoadProgress("Loading application", nbLoaded, nbPackages);
280
+ }));
258
281
  });
259
282
 
260
283
  return Promise.all(promises);