@player-ui/async-node-plugin 0.11.3--canary.666.23690 → 0.11.3--canary.642.23780

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