| 15 | * An error will be logged if you try to disconnect the signal more than once. |
| 16 | */ |
| 17 | export class SignalHandle { |
| 18 | private constructor(target: CanDisconnect, id: number) { |
| 19 | this.target = target; |
| 20 | if (target instanceof Clutter.Actor) { |
| 21 | target.connect('destroy', () => { |
| 22 | this.disconnect(); |
| 23 | }); |
| 24 | } |
| 25 | this.id = id; |
| 26 | } |
| 27 | |
| 28 | /** Creates a new signal handle by subscribing to the `signal` on `to` */ |
| 29 | static connect<F>( |
| 30 | to: CanSendSignal<F>, |
| 31 | signal: string, |
| 32 | callback: F |
| 33 | ): SignalHandle { |
| 34 | return new SignalHandle(to, to.connect(signal, callback)); |
| 35 | } |
| 36 | |
| 37 | private target: CanDisconnect | null; |
| 38 | private id: number; |
| 39 | |
| 40 | /** Disconnects the signal. |
| 41 | * The callback function will not be called again after this. |
| 42 | * |
| 43 | * An error will be logged if you try to disconnect the signal more than once. |
| 44 | */ |
| 45 | disconnect() { |
| 46 | if (this.target == null) { |
| 47 | log('Signal is already disconnected'); |
| 48 | } else { |
| 49 | this.target.disconnect(this.id); |
| 50 | this.target = null; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | export class SignalObserver { |
| 56 | signalObservedList: SignalHandle[]; |
nothing calls this directly
no outgoing calls
no test coverage detected