@player-ui/async-node-plugin 0.8.0--canary.307.9621 → 0.8.0-next.0

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/index.esm.js DELETED
@@ -1,94 +0,0 @@
1
- import { NodeType, getNodeID } from '@player-ui/player';
2
- import { AsyncParallelBailHook } from 'tapable-ts';
3
- import queueMicrotask from 'queue-microtask';
4
- import { omit } from 'timm';
5
-
6
- var __async = (__this, __arguments, generator) => {
7
- return new Promise((resolve, reject) => {
8
- var fulfilled = (value) => {
9
- try {
10
- step(generator.next(value));
11
- } catch (e) {
12
- reject(e);
13
- }
14
- };
15
- var rejected = (value) => {
16
- try {
17
- step(generator.throw(value));
18
- } catch (e) {
19
- reject(e);
20
- }
21
- };
22
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
23
- step((generator = generator.apply(__this, __arguments)).next());
24
- });
25
- };
26
- class AsyncNodePlugin {
27
- constructor() {
28
- this.hooks = {
29
- onAsyncNode: new AsyncParallelBailHook()
30
- };
31
- this.name = "AsyncNode";
32
- this.resolvedMapping = new Map();
33
- }
34
- isAsync(node) {
35
- return (node == null ? void 0 : node.type) === NodeType.Async;
36
- }
37
- apply(player) {
38
- player.hooks.viewController.tap(this.name, (viewController) => {
39
- viewController.hooks.view.tap(this.name, (view) => {
40
- view.hooks.parser.tap(this.name, (parser) => {
41
- parser.hooks.determineNodeType.tap(this.name, (obj) => {
42
- if (Object.prototype.hasOwnProperty.call(obj, "async")) {
43
- return NodeType.Async;
44
- }
45
- });
46
- parser.hooks.parseNode.tap(this.name, (obj, nodeType, options, determinedNodeType) => {
47
- if (determinedNodeType === NodeType.Async) {
48
- const parsedAsync = parser.parseObject(omit(obj, "async"), nodeType, options);
49
- const parsedNodeId = getNodeID(parsedAsync);
50
- if (parsedAsync !== null && parsedNodeId) {
51
- return parser.createASTNode({
52
- id: parsedNodeId,
53
- type: NodeType.Async,
54
- value: parsedAsync
55
- }, obj);
56
- }
57
- return null;
58
- }
59
- });
60
- });
61
- view.hooks.resolver.tap(this.name, (resolver) => {
62
- resolver.hooks.beforeResolve.tap(this.name, (node, options) => {
63
- let resolvedNode;
64
- if (this.isAsync(node)) {
65
- const mappedValue = this.resolvedMapping.get(node.id);
66
- if (mappedValue) {
67
- resolvedNode = mappedValue;
68
- }
69
- } else {
70
- resolvedNode = null;
71
- }
72
- const newNode = resolvedNode || node;
73
- if (!resolvedNode && (node == null ? void 0 : node.type) === NodeType.Async) {
74
- queueMicrotask(() => __async(this, null, function* () {
75
- var _a;
76
- const result = yield this.hooks.onAsyncNode.call(node);
77
- const parsedNode = options.parseNode ? options.parseNode(result) : void 0;
78
- if (parsedNode) {
79
- this.resolvedMapping.set(node.id, parsedNode);
80
- (_a = viewController.currentView) == null ? void 0 : _a.updateAsync();
81
- }
82
- }));
83
- return node;
84
- }
85
- return newNode;
86
- });
87
- });
88
- });
89
- });
90
- }
91
- }
92
-
93
- export { AsyncNodePlugin };
94
- //# sourceMappingURL=index.esm.js.map