@player-ui/async-node-plugin 0.13.0-next.2 → 0.13.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 +114 -48
- package/dist/AsyncNodePlugin.native.js.map +1 -1
- package/dist/cjs/index.cjs +72 -32
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +73 -33
- package/dist/index.mjs +73 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/index.test.ts +274 -9
- package/src/index.ts +125 -46
- package/types/index.d.ts +37 -10
|
@@ -2576,9 +2576,10 @@ var AsyncNodePlugin = function() {
|
|
|
2576
2576
|
var import_timm7 = __toESM(require_timm(), 1);
|
|
2577
2577
|
var import_timm8 = __toESM(require_timm(), 1);
|
|
2578
2578
|
var import_p_defer = __toESM(require_p_defer(), 1);
|
|
2579
|
+
var import_queue_microtask = __toESM(require_queue_microtask(), 1);
|
|
2579
2580
|
var import_p_defer2 = __toESM(require_p_defer(), 1);
|
|
2580
2581
|
var import_timm9 = __toESM(require_timm(), 1);
|
|
2581
|
-
var
|
|
2582
|
+
var import_queue_microtask2 = __toESM(require_queue_microtask(), 1);
|
|
2582
2583
|
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/node_modules/.aspect_rules_js/@player-ui+partial-match-registry@0.0.0/node_modules/@player-ui/partial-match-registry/dist/index.mjs
|
|
2583
2584
|
var import_sorted_array = __toESM(require_sorted_array(), 1);
|
|
2584
2585
|
function traverseObj(object) {
|
|
@@ -7175,7 +7176,7 @@ var AsyncNodePlugin = function() {
|
|
|
7175
7176
|
}
|
|
7176
7177
|
if (!this.pendingUpdate.scheduled && !silent) {
|
|
7177
7178
|
this.pendingUpdate.scheduled = true;
|
|
7178
|
-
(0,
|
|
7179
|
+
(0, import_queue_microtask2.default)(function() {
|
|
7179
7180
|
var _this_pendingUpdate, _this_currentView;
|
|
7180
7181
|
var updates = (_this_pendingUpdate = _this.pendingUpdate) === null || _this_pendingUpdate === void 0 ? void 0 : _this_pendingUpdate.changedBindings;
|
|
7181
7182
|
_this.pendingUpdate = void 0;
|
|
@@ -7853,7 +7854,7 @@ var AsyncNodePlugin = function() {
|
|
|
7853
7854
|
var result = expressionEvaluator.evaluateAsync(exp);
|
|
7854
7855
|
if (isPromiseLike(result)) {
|
|
7855
7856
|
if (value.await) {
|
|
7856
|
-
|
|
7857
|
+
(0, import_queue_microtask.default)(function() {
|
|
7857
7858
|
result.then(function(r) {
|
|
7858
7859
|
return flowController === null || flowController === void 0 ? void 0 : flowController.transition(String(r));
|
|
7859
7860
|
}).catch(flowResultDeferred.reject);
|
|
@@ -8042,7 +8043,7 @@ var AsyncNodePlugin = function() {
|
|
|
8042
8043
|
commit: COMMIT
|
|
8043
8044
|
};
|
|
8044
8045
|
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/index.ts
|
|
8045
|
-
var
|
|
8046
|
+
var import_queue_microtask3 = __toESM(require_queue_microtask());
|
|
8046
8047
|
var import_timm10 = __toESM(require_timm());
|
|
8047
8048
|
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/async-node/core/src/transform.ts
|
|
8048
8049
|
var asyncTransform = function(assetId, wrapperAssetType, asset, flatten2) {
|
|
@@ -8071,7 +8072,8 @@ var AsyncNodePlugin = function() {
|
|
|
8071
8072
|
var _this = this;
|
|
8072
8073
|
_class_call_check(this, AsyncNodePlugin);
|
|
8073
8074
|
this.hooks = {
|
|
8074
|
-
onAsyncNode: new AsyncParallelBailHook()
|
|
8075
|
+
onAsyncNode: new AsyncParallelBailHook(),
|
|
8076
|
+
onAsyncNodeError: new SyncBailHook()
|
|
8075
8077
|
};
|
|
8076
8078
|
this.name = "AsyncNode";
|
|
8077
8079
|
if (options === null || options === void 0 ? void 0 : options.plugins) {
|
|
@@ -8105,10 +8107,17 @@ var AsyncNodePlugin = function() {
|
|
|
8105
8107
|
}
|
|
8106
8108
|
}
|
|
8107
8109
|
_create_class(AsyncNodePlugin, [
|
|
8110
|
+
{
|
|
8111
|
+
key: "getPlayerInstance",
|
|
8112
|
+
value: function getPlayerInstance() {
|
|
8113
|
+
return this.playerInstance;
|
|
8114
|
+
}
|
|
8115
|
+
},
|
|
8108
8116
|
{
|
|
8109
8117
|
key: "apply",
|
|
8110
8118
|
value: function apply(player) {
|
|
8111
8119
|
var _this = this;
|
|
8120
|
+
this.playerInstance = player;
|
|
8112
8121
|
player.hooks.viewController.tap(this.name, function(viewController) {
|
|
8113
8122
|
viewController.hooks.view.tap(_this.name, function(view) {
|
|
8114
8123
|
var _this_plugins;
|
|
@@ -8127,25 +8136,36 @@ var AsyncNodePlugin = function() {
|
|
|
8127
8136
|
_class_call_check(this, AsyncNodePluginPlugin);
|
|
8128
8137
|
this.asyncNode = new AsyncParallelBailHook();
|
|
8129
8138
|
this.name = "AsyncNode";
|
|
8130
|
-
this.resolvedMapping = /* @__PURE__ */ new Map();
|
|
8131
8139
|
}
|
|
8132
8140
|
_create_class(AsyncNodePluginPlugin, [
|
|
8133
8141
|
{
|
|
8134
8142
|
/**
|
|
8143
|
+
* Parses the node from the result and triggers an asynchronous view update if necessary.
|
|
8144
|
+
* @param node The asynchronous node that might be updated.
|
|
8145
|
+
* @param result The result obtained from resolving the async node. This could be any data structure or value.
|
|
8146
|
+
* @param options Options provided for node resolution, including a potential parseNode function to process the result.
|
|
8147
|
+
* @param view The view instance where the node resides. This can be undefined if the view is not currently active.
|
|
8148
|
+
*/ key: "parseNodeAndUpdate",
|
|
8149
|
+
value: function parseNodeAndUpdate(node, context, result, options) {
|
|
8150
|
+
var parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
|
|
8151
|
+
this.handleAsyncUpdate(node, context, parsedNode);
|
|
8152
|
+
}
|
|
8153
|
+
},
|
|
8154
|
+
{
|
|
8155
|
+
/**
|
|
8135
8156
|
* Updates the node asynchronously based on the result provided.
|
|
8136
8157
|
* This method is responsible for handling the update logic of asynchronous nodes.
|
|
8137
8158
|
* It checks if the node needs to be updated based on the new result and updates the mapping accordingly.
|
|
8138
8159
|
* If an update is necessary, it triggers an asynchronous update on the view.
|
|
8139
8160
|
* @param node The asynchronous node that might be updated.
|
|
8140
|
-
* @param
|
|
8141
|
-
* @param options Options provided for node resolution, including a potential parseNode function to process the result.
|
|
8161
|
+
* @param newNode The new node to replace the async node.
|
|
8142
8162
|
* @param view The view instance where the node resides. This can be undefined if the view is not currently active.
|
|
8143
8163
|
*/ key: "handleAsyncUpdate",
|
|
8144
|
-
value: function handleAsyncUpdate(node,
|
|
8145
|
-
var
|
|
8146
|
-
if (
|
|
8147
|
-
|
|
8148
|
-
view
|
|
8164
|
+
value: function handleAsyncUpdate(node, context, newNode) {
|
|
8165
|
+
var nodeResolveCache = context.nodeResolveCache, view = context.view;
|
|
8166
|
+
if (nodeResolveCache.get(node.id) !== newNode) {
|
|
8167
|
+
nodeResolveCache.set(node.id, newNode ? newNode : node);
|
|
8168
|
+
view.updateAsync();
|
|
8149
8169
|
}
|
|
8150
8170
|
}
|
|
8151
8171
|
},
|
|
@@ -8156,47 +8176,86 @@ var AsyncNodePlugin = function() {
|
|
|
8156
8176
|
* @param resolver The resolver instance to attach the hook to.
|
|
8157
8177
|
* @param view
|
|
8158
8178
|
*/ key: "applyResolver",
|
|
8159
|
-
value: function applyResolver(resolver) {
|
|
8179
|
+
value: function applyResolver(resolver, context) {
|
|
8160
8180
|
var _this = this;
|
|
8161
8181
|
resolver.hooks.beforeResolve.tap(this.name, function(node, options) {
|
|
8162
|
-
|
|
8163
|
-
|
|
8164
|
-
var mappedValue = _this.resolvedMapping.get(node.id);
|
|
8165
|
-
if (mappedValue) {
|
|
8166
|
-
resolvedNode = mappedValue;
|
|
8167
|
-
}
|
|
8168
|
-
} else {
|
|
8169
|
-
resolvedNode = null;
|
|
8182
|
+
if (!_this.isAsync(node)) {
|
|
8183
|
+
return node;
|
|
8170
8184
|
}
|
|
8171
|
-
var
|
|
8172
|
-
if (
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
return _ts_generator(this, function(_state) {
|
|
8177
|
-
switch(_state.label){
|
|
8178
|
-
case 0:
|
|
8179
|
-
return [
|
|
8180
|
-
4,
|
|
8181
|
-
(_this_basePlugin = _this1.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node, function(result2) {
|
|
8182
|
-
_this1.handleAsyncUpdate(node, result2, options, _this1.currentView);
|
|
8183
|
-
})
|
|
8184
|
-
];
|
|
8185
|
-
case 1:
|
|
8186
|
-
result = _state.sent();
|
|
8187
|
-
_this1.handleAsyncUpdate(node, result, options, _this1.currentView);
|
|
8188
|
-
return [
|
|
8189
|
-
2
|
|
8190
|
-
];
|
|
8191
|
-
}
|
|
8192
|
-
});
|
|
8193
|
-
}));
|
|
8185
|
+
var resolvedNode = context.nodeResolveCache.get(node.id);
|
|
8186
|
+
if (resolvedNode !== void 0) {
|
|
8187
|
+
return resolvedNode;
|
|
8188
|
+
}
|
|
8189
|
+
if (context.inProgressNodes.has(node.id)) {
|
|
8194
8190
|
return node;
|
|
8195
8191
|
}
|
|
8196
|
-
|
|
8192
|
+
context.inProgressNodes.add(node.id);
|
|
8193
|
+
(0, import_queue_microtask3.default)(function() {
|
|
8194
|
+
_this.runAsyncNode(node, context, options).finally();
|
|
8195
|
+
});
|
|
8196
|
+
return node;
|
|
8197
8197
|
});
|
|
8198
8198
|
}
|
|
8199
8199
|
},
|
|
8200
|
+
{
|
|
8201
|
+
key: "runAsyncNode",
|
|
8202
|
+
value: function runAsyncNode(node, context, options) {
|
|
8203
|
+
var _this = this;
|
|
8204
|
+
return _async_to_generator(function() {
|
|
8205
|
+
var _this_basePlugin, result, e, _this_basePlugin1, _options_logger, error, result1, _this_basePlugin_getPlayerInstance, _this_basePlugin2, playerState;
|
|
8206
|
+
return _ts_generator(this, function(_state) {
|
|
8207
|
+
switch(_state.label){
|
|
8208
|
+
case 0:
|
|
8209
|
+
_state.trys.push([
|
|
8210
|
+
0,
|
|
8211
|
+
2,
|
|
8212
|
+
,
|
|
8213
|
+
3
|
|
8214
|
+
]);
|
|
8215
|
+
return [
|
|
8216
|
+
4,
|
|
8217
|
+
(_this_basePlugin = _this.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node, function(result2) {
|
|
8218
|
+
_this.parseNodeAndUpdate(node, context, result2, options);
|
|
8219
|
+
})
|
|
8220
|
+
];
|
|
8221
|
+
case 1:
|
|
8222
|
+
result = _state.sent();
|
|
8223
|
+
context.inProgressNodes.delete(node.id);
|
|
8224
|
+
_this.parseNodeAndUpdate(node, context, result, options);
|
|
8225
|
+
return [
|
|
8226
|
+
3,
|
|
8227
|
+
3
|
|
8228
|
+
];
|
|
8229
|
+
case 2:
|
|
8230
|
+
e = _state.sent();
|
|
8231
|
+
error = _instanceof(e, Error) ? e : new Error(String(e));
|
|
8232
|
+
result1 = (_this_basePlugin1 = _this.basePlugin) === null || _this_basePlugin1 === void 0 ? void 0 : _this_basePlugin1.hooks.onAsyncNodeError.call(error, node);
|
|
8233
|
+
if (result1 === void 0) {
|
|
8234
|
+
;
|
|
8235
|
+
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();
|
|
8236
|
+
if ((playerState === null || playerState === void 0 ? void 0 : playerState.status) === "in-progress") {
|
|
8237
|
+
playerState.fail(error);
|
|
8238
|
+
}
|
|
8239
|
+
return [
|
|
8240
|
+
2
|
|
8241
|
+
];
|
|
8242
|
+
}
|
|
8243
|
+
(_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);
|
|
8244
|
+
context.inProgressNodes.delete(node.id);
|
|
8245
|
+
_this.parseNodeAndUpdate(node, context, result1, options);
|
|
8246
|
+
return [
|
|
8247
|
+
3,
|
|
8248
|
+
3
|
|
8249
|
+
];
|
|
8250
|
+
case 3:
|
|
8251
|
+
return [
|
|
8252
|
+
2
|
|
8253
|
+
];
|
|
8254
|
+
}
|
|
8255
|
+
});
|
|
8256
|
+
})();
|
|
8257
|
+
}
|
|
8258
|
+
},
|
|
8200
8259
|
{
|
|
8201
8260
|
key: "isAsync",
|
|
8202
8261
|
value: function isAsync(node) {
|
|
@@ -8243,9 +8302,16 @@ var AsyncNodePlugin = function() {
|
|
|
8243
8302
|
{
|
|
8244
8303
|
key: "apply",
|
|
8245
8304
|
value: function apply(view) {
|
|
8246
|
-
|
|
8305
|
+
var _this = this;
|
|
8306
|
+
var context = {
|
|
8307
|
+
nodeResolveCache: /* @__PURE__ */ new Map(),
|
|
8308
|
+
inProgressNodes: /* @__PURE__ */ new Set(),
|
|
8309
|
+
view: view
|
|
8310
|
+
};
|
|
8247
8311
|
view.hooks.parser.tap("async", this.applyParser.bind(this));
|
|
8248
|
-
view.hooks.resolver.tap("async",
|
|
8312
|
+
view.hooks.resolver.tap("async", function(resolver) {
|
|
8313
|
+
_this.applyResolver(resolver, context);
|
|
8314
|
+
});
|
|
8249
8315
|
}
|
|
8250
8316
|
},
|
|
8251
8317
|
{
|