runBundle method

Future runBundle(
  1. int id,
  2. VoltronBundleLoader? loader,
  3. ModuleListener? moduleListener,
  4. RootWidgetViewModel? rootViewModel,
)

Implementation

Future<dynamic> runBundle(
  int id,
  VoltronBundleLoader? loader,
  ModuleListener? moduleListener,
  RootWidgetViewModel? rootViewModel,
) async {
  if (!_isFrameWorkInit) {
    _loadModuleListener = moduleListener;
    _notifyModuleLoaded(
      ModuleLoadStatus.engineUninit,
      "load module error. VoltronBridge not initialized",
      rootViewModel,
    );
    return;
  }
  _loadModuleListener = moduleListener;
  if (rootViewModel != null) {
    rootViewModel.timeMonitor?.startEvent(
      EngineMonitorEventKey.moduleLoadEventLoadBundle,
    );
  }
  if (loader == null) {
    _notifyModuleLoaded(
      ModuleLoadStatus.varialeNull,
      "load module error. jsBundleLoader==null",
      rootViewModel,
    );
    return;
  }

  final bundleUniKey = loader.bundleUniKey;
  if (isEmpty(bundleUniKey)) {
    _notifyModuleLoaded(
      ModuleLoadStatus.varialeNull,
      "load module error. loader.getBundleUniKey=null",
      rootViewModel,
    );
    return;
  }
  if (_loadBundleInfo.contains(bundleUniKey)) {
    _notifyModuleLoaded(
      ModuleLoadStatus.repeatLoad,
      "load module error. loader.getBundleUniKey=$bundleUniKey",
      rootViewModel,
    );
    return true;
  }
  await loader.load(this, (param, e) {
    var success = param == 1;
    if (success) {
      LogUtils.i(_kTag, "load module success");
      _loadBundleInfo.add(bundleUniKey!);
      if (rootViewModel != null) {
        _notifyModuleLoaded(
          ModuleLoadStatus.ok,
          null,
          rootViewModel,
        );
      } else {
        _notifyModuleLoaded(
          ModuleLoadStatus.errRunBundle,
          "load module error. loader.load failed. check the file.",
          rootViewModel,
        );
      }
    } else {
      _notifyModuleLoaded(
        ModuleLoadStatus.errRunBundle,
        "load module error. loader.load failed. check the file.",
        rootViewModel,
      );
    }
  });
}