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

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,8 +7729,7 @@ var AsyncNodePlugin = function() {
7729
7729
  var _this = this;
7730
7730
  _class_call_check(this, AsyncNodePlugin);
7731
7731
  this.hooks = {
7732
- onAsyncNode: new AsyncParallelBailHook(),
7733
- onAsyncNodeError: new SyncBailHook()
7732
+ onAsyncNode: new AsyncParallelBailHook()
7734
7733
  };
7735
7734
  this.name = "AsyncNode";
7736
7735
  if (options === null || options === void 0 ? void 0 : options.plugins) {
@@ -7764,17 +7763,10 @@ var AsyncNodePlugin = function() {
7764
7763
  }
7765
7764
  }
7766
7765
  _create_class(AsyncNodePlugin, [
7767
- {
7768
- key: "getPlayerInstance",
7769
- value: function getPlayerInstance() {
7770
- return this.playerInstance;
7771
- }
7772
- },
7773
7766
  {
7774
7767
  key: "apply",
7775
7768
  value: function apply(player) {
7776
7769
  var _this = this;
7777
- this.playerInstance = player;
7778
7770
  player.hooks.viewController.tap(this.name, function(viewController) {
7779
7771
  viewController.hooks.view.tap(_this.name, function(view) {
7780
7772
  var _this_plugins;
@@ -7798,30 +7790,19 @@ var AsyncNodePlugin = function() {
7798
7790
  _create_class(AsyncNodePluginPlugin, [
7799
7791
  {
7800
7792
  /**
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
- /**
7814
7793
  * Updates the node asynchronously based on the result provided.
7815
7794
  * This method is responsible for handling the update logic of asynchronous nodes.
7816
7795
  * It checks if the node needs to be updated based on the new result and updates the mapping accordingly.
7817
7796
  * If an update is necessary, it triggers an asynchronous update on the view.
7818
7797
  * @param node The asynchronous node that might be updated.
7819
- * @param newNode The new node to replace the async node.
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.
7820
7800
  * @param view The view instance where the node resides. This can be undefined if the view is not currently active.
7821
7801
  */ key: "handleAsyncUpdate",
7822
- value: function handleAsyncUpdate(node, newNode, view) {
7823
- if (this.resolvedMapping.get(node.id) !== newNode) {
7824
- this.resolvedMapping.set(node.id, newNode ? newNode : node);
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);
7825
7806
  view === null || view === void 0 ? void 0 : view.updateAsync();
7826
7807
  }
7827
7808
  }
@@ -7836,77 +7817,44 @@ var AsyncNodePlugin = function() {
7836
7817
  value: function applyResolver(resolver) {
7837
7818
  var _this = this;
7838
7819
  resolver.hooks.beforeResolve.tap(this.name, function(node, options) {
7839
- if (!_this.isAsync(node)) {
7840
- return node;
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;
7841
7828
  }
7842
- var resolvedNode = _this.resolvedMapping.get(node.id);
7843
- if (resolvedNode !== void 0) {
7844
- return resolvedNode;
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
+ }));
7852
+ return node;
7845
7853
  }
7846
- (0, import_queue_microtask2.default)(function() {
7847
- return _this.runAsyncNode(node, options);
7848
- });
7849
- return node;
7854
+ return newNode;
7850
7855
  });
7851
7856
  }
7852
7857
  },
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
- },
7910
7858
  {
7911
7859
  key: "isAsync",
7912
7860
  value: function isAsync(node) {