@player-ui/async-node-plugin 0.11.3--canary.660.23557 → 0.11.3--canary.666.23588

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.
@@ -7731,7 +7731,8 @@ var AsyncNodePlugin = function() {
7731
7731
  var _this = this;
7732
7732
  _class_call_check(this, AsyncNodePlugin);
7733
7733
  this.hooks = {
7734
- onAsyncNode: new AsyncParallelBailHook()
7734
+ onAsyncNode: new AsyncParallelBailHook(),
7735
+ onAsyncNodeError: new SyncBailHook()
7735
7736
  };
7736
7737
  this.name = "AsyncNode";
7737
7738
  if (options === null || options === void 0 ? void 0 : options.plugins) {
@@ -7765,10 +7766,17 @@ var AsyncNodePlugin = function() {
7765
7766
  }
7766
7767
  }
7767
7768
  _create_class(AsyncNodePlugin, [
7769
+ {
7770
+ key: "getPlayerInstance",
7771
+ value: function getPlayerInstance() {
7772
+ return this.playerInstance;
7773
+ }
7774
+ },
7768
7775
  {
7769
7776
  key: "apply",
7770
7777
  value: function apply(player) {
7771
7778
  var _this = this;
7779
+ this.playerInstance = player;
7772
7780
  player.hooks.viewController.tap(this.name, function(viewController) {
7773
7781
  viewController.hooks.view.tap(_this.name, function(view) {
7774
7782
  var _this_plugins;
@@ -7792,19 +7800,30 @@ var AsyncNodePlugin = function() {
7792
7800
  _create_class(AsyncNodePluginPlugin, [
7793
7801
  {
7794
7802
  /**
7803
+ * Parses the node from the result and triggers an asynchronous view update if necessary.
7804
+ * @param node The asynchronous node that might be updated.
7805
+ * @param result The result obtained from resolving the async node. This could be any data structure or value.
7806
+ * @param options Options provided for node resolution, including a potential parseNode function to process the result.
7807
+ * @param view The view instance where the node resides. This can be undefined if the view is not currently active.
7808
+ */ key: "parseNodeAndUpdate",
7809
+ value: function parseNodeAndUpdate(node, result, options, view) {
7810
+ var parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
7811
+ this.handleAsyncUpdate(node, parsedNode, view);
7812
+ }
7813
+ },
7814
+ {
7815
+ /**
7795
7816
  * Updates the node asynchronously based on the result provided.
7796
7817
  * This method is responsible for handling the update logic of asynchronous nodes.
7797
7818
  * It checks if the node needs to be updated based on the new result and updates the mapping accordingly.
7798
7819
  * If an update is necessary, it triggers an asynchronous update on the view.
7799
7820
  * @param node The asynchronous node that might be updated.
7800
- * @param result The result obtained from resolving the async node. This could be any data structure or value.
7801
- * @param options Options provided for node resolution, including a potential parseNode function to process the result.
7821
+ * @param newNode The new node to replace the async node.
7802
7822
  * @param view The view instance where the node resides. This can be undefined if the view is not currently active.
7803
7823
  */ key: "handleAsyncUpdate",
7804
- value: function handleAsyncUpdate(node, result, options, view) {
7805
- var parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
7806
- if (this.resolvedMapping.get(node.id) !== parsedNode) {
7807
- this.resolvedMapping.set(node.id, parsedNode ? parsedNode : node);
7824
+ value: function handleAsyncUpdate(node, newNode, view) {
7825
+ if (this.resolvedMapping.get(node.id) !== newNode) {
7826
+ this.resolvedMapping.set(node.id, newNode ? newNode : node);
7808
7827
  view === null || view === void 0 ? void 0 : view.updateAsync();
7809
7828
  }
7810
7829
  }
@@ -7819,44 +7838,77 @@ var AsyncNodePlugin = function() {
7819
7838
  value: function applyResolver(resolver) {
7820
7839
  var _this = this;
7821
7840
  resolver.hooks.beforeResolve.tap(this.name, function(node, options) {
7822
- var resolvedNode;
7823
- if (_this.isAsync(node)) {
7824
- var mappedValue = _this.resolvedMapping.get(node.id);
7825
- if (mappedValue) {
7826
- resolvedNode = mappedValue;
7827
- }
7828
- } else {
7829
- resolvedNode = null;
7830
- }
7831
- var newNode = resolvedNode || node;
7832
- if (!resolvedNode && (node === null || node === void 0 ? void 0 : node.type) === NodeType.Async) {
7833
- var _this1 = _this;
7834
- (0, import_queue_microtask2.default)(/*#__PURE__*/ _async_to_generator(function() {
7835
- var _this_basePlugin, result;
7836
- return _ts_generator(this, function(_state) {
7837
- switch(_state.label){
7838
- case 0:
7839
- return [
7840
- 4,
7841
- (_this_basePlugin = _this1.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node, function(result2) {
7842
- _this1.handleAsyncUpdate(node, result2, options, _this1.currentView);
7843
- })
7844
- ];
7845
- case 1:
7846
- result = _state.sent();
7847
- _this1.handleAsyncUpdate(node, result, options, _this1.currentView);
7848
- return [
7849
- 2
7850
- ];
7851
- }
7852
- });
7853
- }));
7841
+ if (!_this.isAsync(node)) {
7854
7842
  return node;
7855
7843
  }
7856
- return newNode;
7844
+ var resolvedNode = _this.resolvedMapping.get(node.id);
7845
+ if (resolvedNode !== void 0) {
7846
+ return resolvedNode;
7847
+ }
7848
+ (0, import_queue_microtask2.default)(function() {
7849
+ return _this.runAsyncNode(node, options);
7850
+ });
7851
+ return node;
7857
7852
  });
7858
7853
  }
7859
7854
  },
7855
+ {
7856
+ key: "runAsyncNode",
7857
+ value: function runAsyncNode(node, options) {
7858
+ var _this = this;
7859
+ return _async_to_generator(function() {
7860
+ var _this_basePlugin, result, e, _this_basePlugin1, _options_logger, error, result1, _this_basePlugin_getPlayerInstance, _this_basePlugin2, playerState;
7861
+ return _ts_generator(this, function(_state) {
7862
+ switch(_state.label){
7863
+ case 0:
7864
+ _state.trys.push([
7865
+ 0,
7866
+ 2,
7867
+ ,
7868
+ 3
7869
+ ]);
7870
+ return [
7871
+ 4,
7872
+ (_this_basePlugin = _this.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node, function(result2) {
7873
+ _this.parseNodeAndUpdate(node, result2, options, _this.currentView);
7874
+ })
7875
+ ];
7876
+ case 1:
7877
+ result = _state.sent();
7878
+ _this.parseNodeAndUpdate(node, result, options, _this.currentView);
7879
+ return [
7880
+ 3,
7881
+ 3
7882
+ ];
7883
+ case 2:
7884
+ e = _state.sent();
7885
+ error = _instanceof(e, Error) ? e : new Error(String(e));
7886
+ result1 = (_this_basePlugin1 = _this.basePlugin) === null || _this_basePlugin1 === void 0 ? void 0 : _this_basePlugin1.hooks.onAsyncNodeError.call(error, node);
7887
+ if (result1 === void 0) {
7888
+ ;
7889
+ playerState = (_this_basePlugin2 = _this.basePlugin) === null || _this_basePlugin2 === void 0 ? void 0 : (_this_basePlugin_getPlayerInstance = _this_basePlugin2.getPlayerInstance()) === null || _this_basePlugin_getPlayerInstance === void 0 ? void 0 : _this_basePlugin_getPlayerInstance.getState();
7890
+ if ((playerState === null || playerState === void 0 ? void 0 : playerState.status) === "in-progress") {
7891
+ playerState.fail(error);
7892
+ }
7893
+ return [
7894
+ 2
7895
+ ];
7896
+ }
7897
+ (_options_logger = options.logger) === null || _options_logger === void 0 ? void 0 : _options_logger.error("Async node handling failed and resolved with a fallback. Error:", error);
7898
+ _this.handleAsyncUpdate(node, result1, _this.currentView);
7899
+ return [
7900
+ 3,
7901
+ 3
7902
+ ];
7903
+ case 3:
7904
+ return [
7905
+ 2
7906
+ ];
7907
+ }
7908
+ });
7909
+ })();
7910
+ }
7911
+ },
7860
7912
  {
7861
7913
  key: "isAsync",
7862
7914
  value: function isAsync(node) {