| 88 | #stack; |
| 89 | |
| 90 | constructor(activeChannel, data) { |
| 91 | // eslint-disable-next-line no-restricted-globals |
| 92 | using stack = new DisposableStack(); |
| 93 | |
| 94 | // Enter stores using withScope |
| 95 | if (activeChannel._stores) { |
| 96 | for (const entry of activeChannel._stores.entries()) { |
| 97 | const store = entry[0]; |
| 98 | const transform = entry[1]; |
| 99 | |
| 100 | let newContext = data; |
| 101 | if (transform) { |
| 102 | try { |
| 103 | newContext = transform(data); |
| 104 | } catch (err) { |
| 105 | process.nextTick(() => { |
| 106 | triggerUncaughtException(err, false); |
| 107 | }); |
| 108 | continue; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | stack.use(store.withScope(newContext)); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Publish data |
| 117 | activeChannel.publish(data); |
| 118 | |
| 119 | // Transfer ownership of the stack |
| 120 | this.#stack = stack.move(); |
| 121 | } |
| 122 | |
| 123 | [SymbolDispose]() { |
| 124 | this.#stack[SymbolDispose](); |