1 |
|
2 | import {executionAsyncId, createHook} from "node:async_hooks";
|
3 | import {virtualSheet} from "twind/sheets";
|
4 | export * from "twind";
|
5 | export * from "twind/sheets";
|
6 | var asyncVirtualSheet = () => {
|
7 | const sheet = virtualSheet();
|
8 | const initial = sheet.reset();
|
9 | const store = new Map();
|
10 | const asyncHook = createHook({
|
11 | init(asyncId, type, triggerAsyncId) {
|
12 | const snapshot = store.get(triggerAsyncId);
|
13 | if (snapshot) {
|
14 | store.set(asyncId, snapshot);
|
15 | }
|
16 | },
|
17 | before(asyncId) {
|
18 | const snapshot = store.get(asyncId);
|
19 | if (snapshot) {
|
20 | sheet.reset(snapshot.state);
|
21 | }
|
22 | },
|
23 | after(asyncId) {
|
24 | const snapshot = store.get(asyncId);
|
25 | if (snapshot) {
|
26 | snapshot.state = sheet.reset(initial);
|
27 | }
|
28 | },
|
29 | destroy(asyncId) {
|
30 | store.delete(asyncId);
|
31 | }
|
32 | }).enable();
|
33 | return {
|
34 | get target() {
|
35 | return sheet.target;
|
36 | },
|
37 | insert: sheet.insert,
|
38 | init: sheet.init,
|
39 | reset: () => {
|
40 | const asyncId = executionAsyncId();
|
41 | const snapshot = store.get(asyncId);
|
42 | if (snapshot) {
|
43 | snapshot.state = void 0;
|
44 | } else {
|
45 | store.set(asyncId, {state: void 0});
|
46 | }
|
47 | sheet.reset();
|
48 | },
|
49 | enable: () => asyncHook.enable(),
|
50 | disable: () => asyncHook.disable()
|
51 | };
|
52 | };
|
53 | export {
|
54 | asyncVirtualSheet
|
55 | };
|
56 |
|