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, | ||||
|     editorInkOpacity, | ||||
|   }) { | ||||
|     editorFreeTextFontSize.addEventListener("input", evt => { | ||||
|     const dispatchEvent = (typeStr, value) => { | ||||
|       this.eventBus.dispatch("switchannotationeditorparams", { | ||||
|         source: this, | ||||
|         type: AnnotationEditorParamsType.FREETEXT_SIZE, | ||||
|         value: editorFreeTextFontSize.valueAsNumber, | ||||
|         type: AnnotationEditorParamsType[typeStr], | ||||
|         value, | ||||
|       }); | ||||
|     }; | ||||
|     editorFreeTextFontSize.addEventListener("input", function () { | ||||
|       dispatchEvent("FREETEXT_SIZE", this.valueAsNumber); | ||||
|     }); | ||||
|     editorFreeTextColor.addEventListener("input", evt => { | ||||
|       this.eventBus.dispatch("switchannotationeditorparams", { | ||||
|         source: this, | ||||
|         type: AnnotationEditorParamsType.FREETEXT_COLOR, | ||||
|         value: editorFreeTextColor.value, | ||||
|     editorFreeTextColor.addEventListener("input", function () { | ||||
|       dispatchEvent("FREETEXT_COLOR", this.value); | ||||
|     }); | ||||
|     editorInkColor.addEventListener("input", function () { | ||||
|       dispatchEvent("INK_COLOR", this.value); | ||||
|     }); | ||||
|     editorInkColor.addEventListener("input", evt => { | ||||
|       this.eventBus.dispatch("switchannotationeditorparams", { | ||||
|         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, | ||||
|     editorInkThickness.addEventListener("input", function () { | ||||
|       dispatchEvent("INK_THICKNESS", this.valueAsNumber); | ||||
|     }); | ||||
|     editorInkOpacity.addEventListener("input", function () { | ||||
|       dispatchEvent("INK_OPACITY", this.valueAsNumber); | ||||
|     }); | ||||
| 
 | ||||
|     this.eventBus._on("annotationeditorparamschanged", evt => { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user