()
| 32 | }; |
| 33 | |
| 34 | export function createPanelReturnTargetStore<T>(): PanelReturnTargetStore<T> { |
| 35 | let target: T | null = null; |
| 36 | const listeners = new Set<() => void>(); |
| 37 | |
| 38 | const notify = () => { |
| 39 | for (const listener of [...listeners]) { |
| 40 | listener(); |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | return { |
| 45 | capture(next) { |
| 46 | target = next; |
| 47 | notify(); |
| 48 | }, |
| 49 | clear() { |
| 50 | target = null; |
| 51 | notify(); |
| 52 | }, |
| 53 | consume() { |
| 54 | const current = target; |
| 55 | target = null; |
| 56 | notify(); |
| 57 | return current; |
| 58 | }, |
| 59 | peek() { |
| 60 | return target; |
| 61 | }, |
| 62 | reset() { |
| 63 | target = null; |
| 64 | }, |
| 65 | subscribe(listener) { |
| 66 | listeners.add(listener); |
| 67 | return () => { |
| 68 | listeners.delete(listener); |
| 69 | }; |
| 70 | }, |
| 71 | }; |
| 72 | } |
no outgoing calls
no test coverage detected