| 
									
										
										
										
											2023-03-24 19:21:15 +01:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   import { UIEventSource } from "../../Logic/UIEventSource" | 
					
						
							|  |  |  |   import { onDestroy } from "svelte" | 
					
						
							| 
									
										
										
										
											2023-03-24 19:21:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * For some stupid reason, it is very hard to let {#if} work together with UIEventSources, so we wrap then here | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   export let condition: UIEventSource<boolean> | 
					
						
							|  |  |  |   let _c = condition.data | 
					
						
							|  |  |  |   onDestroy( | 
					
						
							|  |  |  |     condition.addCallback((c) => { | 
					
						
							|  |  |  |       /* Do _not_ abbreviate this as `.addCallback(c => _c = c)`. This is the same as writing `.addCallback(c => {return _c = c})`,  | 
					
						
							| 
									
										
										
										
											2023-03-28 05:13:48 +02:00
										 |  |  |     which will _unregister_ the callback if `c = true`! */ | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |       _c = c | 
					
						
							|  |  |  |       return false | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   ) | 
					
						
							| 
									
										
										
										
											2023-03-24 19:21:15 +01:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | {#if _c} | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   <slot /> | 
					
						
							|  |  |  | {:else} | 
					
						
							|  |  |  |   <slot name="else" /> | 
					
						
							| 
									
										
										
										
											2023-03-24 19:21:15 +01:00
										 |  |  | {/if} |