@player-ui/async-node-plugin 0.8.0-next.3 → 0.8.0-next.4
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.
- package/dist/AsyncNodePlugin.native.js +61 -78
- package/dist/AsyncNodePlugin.native.js.map +1 -1
- package/dist/cjs/index.cjs +53 -51
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +53 -51
- package/dist/index.mjs +53 -51
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.test.ts +105 -9
- package/src/index.ts +74 -67
- package/types/index.d.ts +21 -4
|
@@ -7563,38 +7563,32 @@ var AsyncNodePlugin = function() {
|
|
|
7563
7563
|
}
|
|
7564
7564
|
_create_class(AsyncNodePluginPlugin, [
|
|
7565
7565
|
{
|
|
7566
|
-
|
|
7567
|
-
|
|
7568
|
-
|
|
7569
|
-
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
|
|
7573
|
-
|
|
7574
|
-
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
var parsedNodeId = getNodeID(parsedAsync);
|
|
7583
|
-
if (parsedAsync !== null && parsedNodeId) {
|
|
7584
|
-
return parser.createASTNode({
|
|
7585
|
-
id: parsedNodeId,
|
|
7586
|
-
type: NodeType.Async,
|
|
7587
|
-
value: parsedAsync
|
|
7588
|
-
}, obj);
|
|
7589
|
-
}
|
|
7590
|
-
return null;
|
|
7591
|
-
}
|
|
7592
|
-
});
|
|
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
|
+
}
|
|
7593
7582
|
}
|
|
7594
7583
|
},
|
|
7595
7584
|
{
|
|
7596
|
-
|
|
7597
|
-
|
|
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) {
|
|
7598
7592
|
var _this = this;
|
|
7599
7593
|
resolver.hooks.beforeResolve.tap(this.name, function(node, options) {
|
|
7600
7594
|
var resolvedNode;
|
|
@@ -7610,22 +7604,19 @@ var AsyncNodePlugin = function() {
|
|
|
7610
7604
|
if (!resolvedNode && (node === null || node === void 0 ? void 0 : node.type) === NodeType.Async) {
|
|
7611
7605
|
var _this1 = _this;
|
|
7612
7606
|
(0, import_queue_microtask2.default)(/*#__PURE__*/ _async_to_generator(function() {
|
|
7613
|
-
var _this_basePlugin, result
|
|
7607
|
+
var _this_basePlugin, result;
|
|
7614
7608
|
return _ts_generator(this, function(_state) {
|
|
7615
7609
|
switch(_state.label){
|
|
7616
7610
|
case 0:
|
|
7617
7611
|
return [
|
|
7618
7612
|
4,
|
|
7619
|
-
(_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
|
+
})
|
|
7620
7616
|
];
|
|
7621
7617
|
case 1:
|
|
7622
7618
|
result = _state.sent();
|
|
7623
|
-
|
|
7624
|
-
if (parsedNode) {
|
|
7625
|
-
;
|
|
7626
|
-
_this1.resolvedMapping.set(node.id, parsedNode);
|
|
7627
|
-
(_this_currentView = _this1.currentView) === null || _this_currentView === void 0 ? void 0 : _this_currentView.updateAsync();
|
|
7628
|
-
}
|
|
7619
|
+
_this1.handleAsyncUpdate(node, result, options, _this1.currentView);
|
|
7629
7620
|
return [
|
|
7630
7621
|
2
|
|
7631
7622
|
];
|
|
@@ -7639,51 +7630,43 @@ var AsyncNodePlugin = function() {
|
|
|
7639
7630
|
}
|
|
7640
7631
|
},
|
|
7641
7632
|
{
|
|
7642
|
-
key: "
|
|
7643
|
-
value: function
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
|
|
7647
|
-
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
7655
|
-
|
|
7656
|
-
|
|
7657
|
-
var
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7665
|
-
return [
|
|
7666
|
-
4,
|
|
7667
|
-
(_this_basePlugin = _this1.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node)
|
|
7668
|
-
];
|
|
7669
|
-
case 1:
|
|
7670
|
-
result = _state.sent();
|
|
7671
|
-
parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
|
|
7672
|
-
_this1.resolvedMapping.set(node.id, parsedNode ? parsedNode : node);
|
|
7673
|
-
view.updateAsync();
|
|
7674
|
-
return [
|
|
7675
|
-
2
|
|
7676
|
-
];
|
|
7677
|
-
}
|
|
7678
|
-
});
|
|
7679
|
-
}));
|
|
7680
|
-
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);
|
|
7681
7656
|
}
|
|
7682
|
-
return
|
|
7683
|
-
}
|
|
7657
|
+
return null;
|
|
7658
|
+
}
|
|
7684
7659
|
});
|
|
7685
7660
|
}
|
|
7686
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
|
+
},
|
|
7687
7670
|
{
|
|
7688
7671
|
key: "applyPlugin",
|
|
7689
7672
|
value: function applyPlugin(asyncNodePlugin) {
|