@player-ui/async-node-plugin 0.8.0-next.4 → 0.8.0-next.5

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/src/index.ts CHANGED
@@ -4,6 +4,7 @@ import type {
4
4
  PlayerPlugin,
5
5
  Node,
6
6
  ParseObjectOptions,
7
+ ParseObjectChildOptions,
7
8
  ViewInstance,
8
9
  Parser,
9
10
  ViewPlugin,
@@ -142,39 +143,52 @@ export class AsyncNodePluginPlugin implements AsyncNodeViewPlugin {
142
143
  return node?.type === NodeType.Async;
143
144
  }
144
145
 
146
+ private isDeterminedAsync(obj: any) {
147
+ return obj && Object.prototype.hasOwnProperty.call(obj, "async");
148
+ }
149
+
145
150
  applyParser(parser: Parser) {
146
- parser.hooks.determineNodeType.tap(this.name, (obj) => {
147
- if (Object.prototype.hasOwnProperty.call(obj, "async")) {
148
- return NodeType.Async;
149
- }
150
- });
151
151
  parser.hooks.parseNode.tap(
152
152
  this.name,
153
153
  (
154
154
  obj: any,
155
155
  nodeType: Node.ChildrenTypes,
156
156
  options: ParseObjectOptions,
157
- determinedNodeType: null | NodeType,
157
+ childOptions?: ParseObjectChildOptions,
158
158
  ) => {
159
- if (determinedNodeType === NodeType.Async) {
159
+ if (this.isDeterminedAsync(obj)) {
160
160
  const parsedAsync = parser.parseObject(
161
161
  omit(obj, "async"),
162
162
  nodeType,
163
163
  options,
164
164
  );
165
165
  const parsedNodeId = getNodeID(parsedAsync);
166
- if (parsedAsync !== null && parsedNodeId) {
167
- return parser.createASTNode(
168
- {
169
- id: parsedNodeId,
170
- type: NodeType.Async,
171
- value: parsedAsync,
172
- },
173
- obj,
174
- );
166
+
167
+ if (parsedAsync === null || !parsedNodeId) {
168
+ return childOptions ? [] : null;
169
+ }
170
+
171
+ const asyncAST = parser.createASTNode(
172
+ {
173
+ id: parsedNodeId,
174
+ type: NodeType.Async,
175
+ value: parsedAsync,
176
+ },
177
+ obj,
178
+ );
179
+
180
+ if (childOptions) {
181
+ return asyncAST
182
+ ? [
183
+ {
184
+ path: [...childOptions.path, childOptions.key],
185
+ value: asyncAST,
186
+ },
187
+ ]
188
+ : [];
175
189
  }
176
190
 
177
- return null;
191
+ return asyncAST;
178
192
  }
179
193
  },
180
194
  );
package/types/index.d.ts CHANGED
@@ -48,6 +48,7 @@ export declare class AsyncNodePluginPlugin implements AsyncNodeViewPlugin {
48
48
  */
49
49
  applyResolver(resolver: Resolver): void;
50
50
  private isAsync;
51
+ private isDeterminedAsync;
51
52
  applyParser(parser: Parser): void;
52
53
  apply(view: ViewInstance): void;
53
54
  applyPlugin(asyncNodePlugin: AsyncNodePlugin): void;