Reduce duplication when dispatching the "switchannotationeditorparams" event
Currently we repeat virtually the same code multiple times, which can be avoided by the introduction of a simple helper function.
This commit is contained in:
		
							parent
							
								
									b135dadb17
								
							
						
					
					
						commit
						d256168b62
					
				| @ -32,40 +32,27 @@ class AnnotationEditorParams { | |||||||
|     editorInkThickness, |     editorInkThickness, | ||||||
|     editorInkOpacity, |     editorInkOpacity, | ||||||
|   }) { |   }) { | ||||||
|     editorFreeTextFontSize.addEventListener("input", evt => { |     const dispatchEvent = (typeStr, value) => { | ||||||
|       this.eventBus.dispatch("switchannotationeditorparams", { |       this.eventBus.dispatch("switchannotationeditorparams", { | ||||||
|         source: this, |         source: this, | ||||||
|         type: AnnotationEditorParamsType.FREETEXT_SIZE, |         type: AnnotationEditorParamsType[typeStr], | ||||||
|         value: editorFreeTextFontSize.valueAsNumber, |         value, | ||||||
|       }); |       }); | ||||||
|  |     }; | ||||||
|  |     editorFreeTextFontSize.addEventListener("input", function () { | ||||||
|  |       dispatchEvent("FREETEXT_SIZE", this.valueAsNumber); | ||||||
|     }); |     }); | ||||||
|     editorFreeTextColor.addEventListener("input", evt => { |     editorFreeTextColor.addEventListener("input", function () { | ||||||
|       this.eventBus.dispatch("switchannotationeditorparams", { |       dispatchEvent("FREETEXT_COLOR", this.value); | ||||||
|         source: this, |  | ||||||
|         type: AnnotationEditorParamsType.FREETEXT_COLOR, |  | ||||||
|         value: editorFreeTextColor.value, |  | ||||||
|     }); |     }); | ||||||
|  |     editorInkColor.addEventListener("input", function () { | ||||||
|  |       dispatchEvent("INK_COLOR", this.value); | ||||||
|     }); |     }); | ||||||
|     editorInkColor.addEventListener("input", evt => { |     editorInkThickness.addEventListener("input", function () { | ||||||
|       this.eventBus.dispatch("switchannotationeditorparams", { |       dispatchEvent("INK_THICKNESS", this.valueAsNumber); | ||||||
|         source: this, |  | ||||||
|         type: AnnotationEditorParamsType.INK_COLOR, |  | ||||||
|         value: editorInkColor.value, |  | ||||||
|       }); |  | ||||||
|     }); |  | ||||||
|     editorInkThickness.addEventListener("input", evt => { |  | ||||||
|       this.eventBus.dispatch("switchannotationeditorparams", { |  | ||||||
|         source: this, |  | ||||||
|         type: AnnotationEditorParamsType.INK_THICKNESS, |  | ||||||
|         value: editorInkThickness.valueAsNumber, |  | ||||||
|       }); |  | ||||||
|     }); |  | ||||||
|     editorInkOpacity.addEventListener("input", evt => { |  | ||||||
|       this.eventBus.dispatch("switchannotationeditorparams", { |  | ||||||
|         source: this, |  | ||||||
|         type: AnnotationEditorParamsType.INK_OPACITY, |  | ||||||
|         value: editorInkOpacity.valueAsNumber, |  | ||||||
|     }); |     }); | ||||||
|  |     editorInkOpacity.addEventListener("input", function () { | ||||||
|  |       dispatchEvent("INK_OPACITY", this.valueAsNumber); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     this.eventBus._on("annotationeditorparamschanged", evt => { |     this.eventBus._on("annotationeditorparamschanged", evt => { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user