loadModule method

Future loadModule(
  1. ModuleLoadParams loadParams,
  2. RootWidgetViewModel viewModel, {
  3. ModuleListener? listener,
  4. ModuleErrorBuilder? moduleStatusBuilder,
  5. OnLoadCompleteListener? onLoadCompleteListener,
})

Implementation

Future<dynamic> loadModule(
  ModuleLoadParams loadParams,
  RootWidgetViewModel viewModel, {
  ModuleListener? listener,
  ModuleErrorBuilder? moduleStatusBuilder,
  OnLoadCompleteListener? onLoadCompleteListener,
}) async {
  LogUtils.dBridge("load module start");
  loadParams.jsParams ??= VoltronMap();
  if (!isEmpty(loadParams.jsAssetsPath)) {
    loadParams.jsParams!.push("sourcePath", loadParams.jsAssetsPath);
  } else if (!isEmpty(loadParams.jsFilePath)) {
    loadParams.jsParams!.push("sourcePath", loadParams.jsFilePath);
  } else if (!isEmpty(loadParams.jsHttpPath)) {
    loadParams.jsParams!.push("sourcePath", loadParams.jsHttpPath);
  }
  _engineContext!.renderContext.addRootViewModel(viewModel);
  _moduleLoadParamsMap[viewModel.id] = loadParams;
  _moduleListener = listener;
  _engineContext?.engineMonitor.initLoadParams(loadParams.jsParams!);
  if (onLoadCompleteListener != null) {
    viewModel.onLoadCompleteListener = onLoadCompleteListener;
  }
  var timeMonitor = TimeMonitor(true);
  viewModel.timeMonitor = timeMonitor;
  timeMonitor.begin();
  timeMonitor.startEvent(EngineMonitorEventKey.moduleLoadEventWaitEngine);
  viewModel.onResumeAndPauseListener = this;
  _devSupportManager.attachToHost(viewModel);
  if (!_devManagerInitFlag && _debugMode) {
    _devManagerInitFlag = true;
  }
  LogUtils.d(_kTag, "internalLoadInstance start...");
  if (_currentState == EngineState.inited) {
    _loadJSInstance(viewModel);
  } else {
    _notifyModuleLoaded(
      ModuleLoadStatus.engineUninit,
      "error wrong state, Engine state not INITED, state: $_currentState",
      viewModel,
    );
  }
}