@player-ui/async-node-plugin 0.11.3--canary.666.24188 → 0.11.3--canary.677.24219
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 +43 -101
- package/dist/AsyncNodePlugin.native.js.map +1 -1
- package/dist/cjs/index.cjs +30 -67
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +31 -68
- package/dist/index.mjs +31 -68
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/index.test.ts +9 -207
- package/src/index.ts +41 -109
- package/types/index.d.ts +9 -30
|
@@ -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;
|
|
@@ -7793,35 +7785,24 @@ var AsyncNodePlugin = function() {
|
|
|
7793
7785
|
_class_call_check(this, AsyncNodePluginPlugin);
|
|
7794
7786
|
this.asyncNode = new AsyncParallelBailHook();
|
|
7795
7787
|
this.name = "AsyncNode";
|
|
7788
|
+
this.resolvedMapping = /* @__PURE__ */ new Map();
|
|
7796
7789
|
}
|
|
7797
7790
|
_create_class(AsyncNodePluginPlugin, [
|
|
7798
7791
|
{
|
|
7799
7792
|
/**
|
|
7800
|
-
* Parses the node from the result and triggers an asynchronous view update if necessary.
|
|
7801
|
-
* @param node The asynchronous node that might be updated.
|
|
7802
|
-
* @param result The result obtained from resolving the async node. This could be any data structure or value.
|
|
7803
|
-
* @param options Options provided for node resolution, including a potential parseNode function to process the result.
|
|
7804
|
-
* @param view The view instance where the node resides. This can be undefined if the view is not currently active.
|
|
7805
|
-
*/ key: "parseNodeAndUpdate",
|
|
7806
|
-
value: function parseNodeAndUpdate(node, context, result, options, view) {
|
|
7807
|
-
var parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
|
|
7808
|
-
this.handleAsyncUpdate(node, context, parsedNode, view);
|
|
7809
|
-
}
|
|
7810
|
-
},
|
|
7811
|
-
{
|
|
7812
|
-
/**
|
|
7813
7793
|
* Updates the node asynchronously based on the result provided.
|
|
7814
7794
|
* This method is responsible for handling the update logic of asynchronous nodes.
|
|
7815
7795
|
* It checks if the node needs to be updated based on the new result and updates the mapping accordingly.
|
|
7816
7796
|
* If an update is necessary, it triggers an asynchronous update on the view.
|
|
7817
7797
|
* @param node The asynchronous node that might be updated.
|
|
7818
|
-
* @param
|
|
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
7800
|
* @param view The view instance where the node resides. This can be undefined if the view is not currently active.
|
|
7820
7801
|
*/ key: "handleAsyncUpdate",
|
|
7821
|
-
value: function handleAsyncUpdate(node,
|
|
7822
|
-
var
|
|
7823
|
-
if (
|
|
7824
|
-
|
|
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
|
}
|
|
@@ -7833,80 +7814,47 @@ var AsyncNodePlugin = function() {
|
|
|
7833
7814
|
* @param resolver The resolver instance to attach the hook to.
|
|
7834
7815
|
* @param view
|
|
7835
7816
|
*/ key: "applyResolver",
|
|
7836
|
-
value: function applyResolver(resolver
|
|
7817
|
+
value: function applyResolver(resolver) {
|
|
7837
7818
|
var _this = this;
|
|
7838
7819
|
resolver.hooks.beforeResolve.tap(this.name, function(node, options) {
|
|
7839
|
-
|
|
7840
|
-
|
|
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
|
|
7843
|
-
if (resolvedNode
|
|
7844
|
-
|
|
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
|
-
|
|
7847
|
-
return _this.runAsyncNode(node, context, options);
|
|
7848
|
-
});
|
|
7849
|
-
return node;
|
|
7854
|
+
return newNode;
|
|
7850
7855
|
});
|
|
7851
7856
|
}
|
|
7852
7857
|
},
|
|
7853
|
-
{
|
|
7854
|
-
key: "runAsyncNode",
|
|
7855
|
-
value: function runAsyncNode(node, context, 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, context, result2, options, _this.currentView);
|
|
7872
|
-
})
|
|
7873
|
-
];
|
|
7874
|
-
case 1:
|
|
7875
|
-
result = _state.sent();
|
|
7876
|
-
_this.parseNodeAndUpdate(node, context, 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, context, 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) {
|
|
@@ -7953,15 +7901,9 @@ var AsyncNodePlugin = function() {
|
|
|
7953
7901
|
{
|
|
7954
7902
|
key: "apply",
|
|
7955
7903
|
value: function apply(view) {
|
|
7956
|
-
var _this = this;
|
|
7957
7904
|
this.currentView = view;
|
|
7958
|
-
var context = {
|
|
7959
|
-
nodeResolveCache: /* @__PURE__ */ new Map()
|
|
7960
|
-
};
|
|
7961
7905
|
view.hooks.parser.tap("async", this.applyParser.bind(this));
|
|
7962
|
-
view.hooks.resolver.tap("async",
|
|
7963
|
-
_this.applyResolver(resolver, context);
|
|
7964
|
-
});
|
|
7906
|
+
view.hooks.resolver.tap("async", this.applyResolver.bind(this));
|
|
7965
7907
|
}
|
|
7966
7908
|
},
|
|
7967
7909
|
{
|