@player-ui/async-node-plugin 0.7.5--canary.443.15749 → 0.7.5--canary.449.15808

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.
@@ -2622,6 +2622,12 @@ var AsyncNodePlugin = function() {
2622
2622
  value: function clear() {
2623
2623
  this.store = createSortedArray();
2624
2624
  }
2625
+ },
2626
+ {
2627
+ /** Check if the registry is empty*/ key: "isRegistryEmpty",
2628
+ value: function isRegistryEmpty() {
2629
+ return this.store.array.length === 0;
2630
+ }
2625
2631
  }
2626
2632
  ]);
2627
2633
  return Registry;
@@ -7557,38 +7563,32 @@ var AsyncNodePlugin = function() {
7557
7563
  }
7558
7564
  _create_class(AsyncNodePluginPlugin, [
7559
7565
  {
7560
- key: "isAsync",
7561
- value: function isAsync(node) {
7562
- return (node === null || node === void 0 ? void 0 : node.type) === NodeType.Async;
7563
- }
7564
- },
7565
- {
7566
- key: "applyParser",
7567
- value: function applyParser(parser) {
7568
- parser.hooks.determineNodeType.tap(this.name, function(obj) {
7569
- if (Object.prototype.hasOwnProperty.call(obj, "async")) {
7570
- return NodeType.Async;
7571
- }
7572
- });
7573
- parser.hooks.parseNode.tap(this.name, function(obj, nodeType, options, determinedNodeType) {
7574
- if (determinedNodeType === NodeType.Async) {
7575
- var parsedAsync = parser.parseObject((0, import_timm10.omit)(obj, "async"), nodeType, options);
7576
- var parsedNodeId = getNodeID(parsedAsync);
7577
- if (parsedAsync !== null && parsedNodeId) {
7578
- return parser.createASTNode({
7579
- id: parsedNodeId,
7580
- type: NodeType.Async,
7581
- value: parsedAsync
7582
- }, obj);
7583
- }
7584
- return null;
7585
- }
7586
- });
7566
+ /**
7567
+ * Updates the node asynchronously based on the result provided.
7568
+ * This method is responsible for handling the update logic of asynchronous nodes.
7569
+ * It checks if the node needs to be updated based on the new result and updates the mapping accordingly.
7570
+ * If an update is necessary, it triggers an asynchronous update on the view.
7571
+ * @param node The asynchronous node that might be updated.
7572
+ * @param result The result obtained from resolving the async node. This could be any data structure or value.
7573
+ * @param options Options provided for node resolution, including a potential parseNode function to process the result.
7574
+ * @param view The view instance where the node resides. This can be undefined if the view is not currently active.
7575
+ */ key: "handleAsyncUpdate",
7576
+ value: function handleAsyncUpdate(node, result, options, view) {
7577
+ var parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
7578
+ if (this.resolvedMapping.get(node.id) !== parsedNode) {
7579
+ this.resolvedMapping.set(node.id, parsedNode ? parsedNode : node);
7580
+ view === null || view === void 0 ? void 0 : view.updateAsync();
7581
+ }
7587
7582
  }
7588
7583
  },
7589
7584
  {
7590
- key: "applyResolverHooks",
7591
- value: function applyResolverHooks(resolver) {
7585
+ /**
7586
+ * Handles the asynchronous API integration for resolving nodes.
7587
+ * This method sets up a hook on the resolver's `beforeResolve` event to process async nodes.
7588
+ * @param resolver The resolver instance to attach the hook to.
7589
+ * @param view
7590
+ */ key: "applyResolver",
7591
+ value: function applyResolver(resolver) {
7592
7592
  var _this = this;
7593
7593
  resolver.hooks.beforeResolve.tap(this.name, function(node, options) {
7594
7594
  var resolvedNode;
@@ -7604,22 +7604,19 @@ var AsyncNodePlugin = function() {
7604
7604
  if (!resolvedNode && (node === null || node === void 0 ? void 0 : node.type) === NodeType.Async) {
7605
7605
  var _this1 = _this;
7606
7606
  (0, import_queue_microtask2.default)(/*#__PURE__*/ _async_to_generator(function() {
7607
- var _this_basePlugin, result, parsedNode, _this_currentView;
7607
+ var _this_basePlugin, result;
7608
7608
  return _ts_generator(this, function(_state) {
7609
7609
  switch(_state.label){
7610
7610
  case 0:
7611
7611
  return [
7612
7612
  4,
7613
- (_this_basePlugin = _this1.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node)
7613
+ (_this_basePlugin = _this1.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node, function(result2) {
7614
+ _this1.handleAsyncUpdate(node, result2, options, _this1.currentView);
7615
+ })
7614
7616
  ];
7615
7617
  case 1:
7616
7618
  result = _state.sent();
7617
- parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
7618
- if (parsedNode) {
7619
- ;
7620
- _this1.resolvedMapping.set(node.id, parsedNode);
7621
- (_this_currentView = _this1.currentView) === null || _this_currentView === void 0 ? void 0 : _this_currentView.updateAsync();
7622
- }
7619
+ _this1.handleAsyncUpdate(node, result, options, _this1.currentView);
7623
7620
  return [
7624
7621
  2
7625
7622
  ];
@@ -7633,51 +7630,43 @@ var AsyncNodePlugin = function() {
7633
7630
  }
7634
7631
  },
7635
7632
  {
7636
- key: "apply",
7637
- value: function apply(view) {
7638
- var _this = this;
7639
- view.hooks.parser.tap("template", this.applyParser.bind(this));
7640
- view.hooks.resolver.tap("template", function(resolver) {
7641
- resolver.hooks.beforeResolve.tap(_this.name, function(node, options) {
7642
- var resolvedNode;
7643
- if (_this.isAsync(node)) {
7644
- var mappedValue = _this.resolvedMapping.get(node.id);
7645
- if (mappedValue) {
7646
- resolvedNode = mappedValue;
7647
- }
7648
- } else {
7649
- resolvedNode = null;
7650
- }
7651
- var newNode = resolvedNode || node;
7652
- if (!resolvedNode && (node === null || node === void 0 ? void 0 : node.type) === NodeType.Async) {
7653
- var _this1 = _this;
7654
- (0, import_queue_microtask2.default)(/*#__PURE__*/ _async_to_generator(function() {
7655
- var _this_basePlugin, result, parsedNode;
7656
- return _ts_generator(this, function(_state) {
7657
- switch(_state.label){
7658
- case 0:
7659
- return [
7660
- 4,
7661
- (_this_basePlugin = _this1.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node)
7662
- ];
7663
- case 1:
7664
- result = _state.sent();
7665
- parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
7666
- _this1.resolvedMapping.set(node.id, parsedNode ? parsedNode : node);
7667
- view.updateAsync();
7668
- return [
7669
- 2
7670
- ];
7671
- }
7672
- });
7673
- }));
7674
- return node;
7633
+ key: "isAsync",
7634
+ value: function isAsync(node) {
7635
+ return (node === null || node === void 0 ? void 0 : node.type) === NodeType.Async;
7636
+ }
7637
+ },
7638
+ {
7639
+ key: "applyParser",
7640
+ value: function applyParser(parser) {
7641
+ parser.hooks.determineNodeType.tap(this.name, function(obj) {
7642
+ if (Object.prototype.hasOwnProperty.call(obj, "async")) {
7643
+ return NodeType.Async;
7644
+ }
7645
+ });
7646
+ parser.hooks.parseNode.tap(this.name, function(obj, nodeType, options, determinedNodeType) {
7647
+ if (determinedNodeType === NodeType.Async) {
7648
+ var parsedAsync = parser.parseObject((0, import_timm10.omit)(obj, "async"), nodeType, options);
7649
+ var parsedNodeId = getNodeID(parsedAsync);
7650
+ if (parsedAsync !== null && parsedNodeId) {
7651
+ return parser.createASTNode({
7652
+ id: parsedNodeId,
7653
+ type: NodeType.Async,
7654
+ value: parsedAsync
7655
+ }, obj);
7675
7656
  }
7676
- return newNode;
7677
- });
7657
+ return null;
7658
+ }
7678
7659
  });
7679
7660
  }
7680
7661
  },
7662
+ {
7663
+ key: "apply",
7664
+ value: function apply(view) {
7665
+ this.currentView = view;
7666
+ view.hooks.parser.tap("async", this.applyParser.bind(this));
7667
+ view.hooks.resolver.tap("async", this.applyResolver.bind(this));
7668
+ }
7669
+ },
7681
7670
  {
7682
7671
  key: "applyPlugin",
7683
7672
  value: function applyPlugin(asyncNodePlugin) {