@player-ui/async-node-plugin 0.13.0-next.2 → 0.13.0-next.3

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.
@@ -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 import_queue_microtask = __toESM(require_queue_microtask(), 1);
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, import_queue_microtask.default)(function() {
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
- queueMicrotask(function() {
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 import_queue_microtask2 = __toESM(require_queue_microtask());
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 result The result obtained from resolving the async node. This could be any data structure or value.
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, result, options, view) {
8145
- var parsedNode = options.parseNode && result ? options.parseNode(result) : void 0;
8146
- if (this.resolvedMapping.get(node.id) !== parsedNode) {
8147
- this.resolvedMapping.set(node.id, parsedNode ? parsedNode : node);
8148
- view === null || view === void 0 ? void 0 : view.updateAsync();
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,80 @@ 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
- var resolvedNode;
8163
- if (_this.isAsync(node)) {
8164
- var mappedValue = _this.resolvedMapping.get(node.id);
8165
- if (mappedValue) {
8166
- resolvedNode = mappedValue;
8167
- }
8168
- } else {
8169
- resolvedNode = null;
8170
- }
8171
- var newNode = resolvedNode || node;
8172
- if (!resolvedNode && (node === null || node === void 0 ? void 0 : node.type) === NodeType.Async) {
8173
- var _this1 = _this;
8174
- (0, import_queue_microtask2.default)(/*#__PURE__*/ _async_to_generator(function() {
8175
- var _this_basePlugin, result;
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
- }));
8182
+ if (!_this.isAsync(node)) {
8194
8183
  return node;
8195
8184
  }
8196
- return newNode;
8185
+ var resolvedNode = context.nodeResolveCache.get(node.id);
8186
+ if (resolvedNode !== void 0) {
8187
+ return resolvedNode;
8188
+ }
8189
+ (0, import_queue_microtask3.default)(function() {
8190
+ return _this.runAsyncNode(node, context, options);
8191
+ });
8192
+ return node;
8197
8193
  });
8198
8194
  }
8199
8195
  },
8196
+ {
8197
+ key: "runAsyncNode",
8198
+ value: function runAsyncNode(node, context, options) {
8199
+ var _this = this;
8200
+ return _async_to_generator(function() {
8201
+ var _this_basePlugin, result, e, _this_basePlugin1, _options_logger, error, result1, _this_basePlugin_getPlayerInstance, _this_basePlugin2, playerState;
8202
+ return _ts_generator(this, function(_state) {
8203
+ switch(_state.label){
8204
+ case 0:
8205
+ _state.trys.push([
8206
+ 0,
8207
+ 2,
8208
+ ,
8209
+ 3
8210
+ ]);
8211
+ return [
8212
+ 4,
8213
+ (_this_basePlugin = _this.basePlugin) === null || _this_basePlugin === void 0 ? void 0 : _this_basePlugin.hooks.onAsyncNode.call(node, function(result2) {
8214
+ _this.parseNodeAndUpdate(node, context, result2, options);
8215
+ })
8216
+ ];
8217
+ case 1:
8218
+ result = _state.sent();
8219
+ _this.parseNodeAndUpdate(node, context, result, options);
8220
+ return [
8221
+ 3,
8222
+ 3
8223
+ ];
8224
+ case 2:
8225
+ e = _state.sent();
8226
+ error = _instanceof(e, Error) ? e : new Error(String(e));
8227
+ result1 = (_this_basePlugin1 = _this.basePlugin) === null || _this_basePlugin1 === void 0 ? void 0 : _this_basePlugin1.hooks.onAsyncNodeError.call(error, node);
8228
+ if (result1 === void 0) {
8229
+ ;
8230
+ 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();
8231
+ if ((playerState === null || playerState === void 0 ? void 0 : playerState.status) === "in-progress") {
8232
+ playerState.fail(error);
8233
+ }
8234
+ return [
8235
+ 2
8236
+ ];
8237
+ }
8238
+ (_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);
8239
+ _this.parseNodeAndUpdate(node, context, result1, options);
8240
+ return [
8241
+ 3,
8242
+ 3
8243
+ ];
8244
+ case 3:
8245
+ return [
8246
+ 2
8247
+ ];
8248
+ }
8249
+ });
8250
+ })();
8251
+ }
8252
+ },
8200
8253
  {
8201
8254
  key: "isAsync",
8202
8255
  value: function isAsync(node) {
@@ -8243,9 +8296,15 @@ var AsyncNodePlugin = function() {
8243
8296
  {
8244
8297
  key: "apply",
8245
8298
  value: function apply(view) {
8246
- this.currentView = view;
8299
+ var _this = this;
8300
+ var context = {
8301
+ nodeResolveCache: /* @__PURE__ */ new Map(),
8302
+ view: view
8303
+ };
8247
8304
  view.hooks.parser.tap("async", this.applyParser.bind(this));
8248
- view.hooks.resolver.tap("async", this.applyResolver.bind(this));
8305
+ view.hooks.resolver.tap("async", function(resolver) {
8306
+ _this.applyResolver(resolver, context);
8307
+ });
8249
8308
  }
8250
8309
  },
8251
8310
  {