@player-ui/async-node-plugin 0.11.3--canary.670.24048 → 0.11.3--canary.666.24070

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