@player-ui/async-node-plugin 0.8.0-next.4 → 0.8.0-next.6
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 +249 -262
- package/dist/AsyncNodePlugin.native.js.map +1 -1
- package/dist/cjs/index.cjs +23 -16
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +23 -16
- package/dist/index.mjs +23 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.test.ts +421 -401
- package/src/index.ts +31 -17
- package/types/index.d.ts +1 -0
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
|
-
|
|
157
|
+
childOptions?: ParseObjectChildOptions,
|
|
158
158
|
) => {
|
|
159
|
-
if (
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
|
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;
|