mirror of
				https://github.com/roc-lang/roc.git
				synced 2025-10-31 13:14:20 +00:00 
			
		
		
		
	 057a18573a
			
		
	
	
		057a18573a
		
			
		
	
	
	
	
		
			
			Implements the new `module` header syntax as described in "module and package changes" [1]: ``` module [Request, Response, req] ``` The old syntax should still work fine, and is automatically upgraded to the new one when running `roc format`. [1] https://docs.google.com/document/d/1E_77fO-44BtoBtXoVeWyGh1xN2KRTWTu8q6i25RNNx0/edit
		
			
				
	
	
		
			77 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
| module [
 | |
|     Handler,
 | |
|     CyclicStructureAccessor,
 | |
|     on,
 | |
|     custom,
 | |
|     onClick,
 | |
|     onDoubleClick,
 | |
|     onMouseDown,
 | |
|     onMouseUp,
 | |
|     onMouseEnter,
 | |
|     onMouseLeave,
 | |
|     onMouseOver,
 | |
|     onMouseOut,
 | |
|     onCheck,
 | |
|     onBlur,
 | |
|     onFocus,
 | |
|     onInput,
 | |
|     onSubmit,
 | |
| ]
 | |
| 
 | |
| import Action exposing [Action]
 | |
| import Html.Internal.Shared exposing [Attribute]
 | |
| 
 | |
| Handler state : Html.Internal.Shared.Handler state
 | |
| CyclicStructureAccessor : Html.Internal.Shared.CyclicStructureAccessor
 | |
| 
 | |
| custom : Str, List CyclicStructureAccessor, (state, List (List U8) -> { action : Action state, stopPropagation : Bool, preventDefault : Bool }) -> Attribute state
 | |
| custom = \eventName, accessors, callback ->
 | |
|     EventListener eventName accessors (Custom callback)
 | |
| 
 | |
| on : Str, List CyclicStructureAccessor, (state, List (List U8) -> Action state) -> Attribute state
 | |
| on = \eventName, accessors, callback ->
 | |
|     EventListener eventName accessors (Normal callback)
 | |
| 
 | |
| # Internal helper
 | |
| curriedOn : Str -> (List CyclicStructureAccessor, (state, List (List U8) -> Action state) -> Attribute state)
 | |
| curriedOn = \eventName ->
 | |
|     \accessors, callback ->
 | |
|         EventListener eventName accessors (Normal callback)
 | |
| 
 | |
| onClick = curriedOn "click"
 | |
| onDoubleClick = curriedOn "dblclick"
 | |
| onMouseDown = curriedOn "mousedown"
 | |
| onMouseUp = curriedOn "mouseup"
 | |
| onMouseEnter = curriedOn "mouseenter"
 | |
| onMouseLeave = curriedOn "mouseleave"
 | |
| onMouseOver = curriedOn "mouseover"
 | |
| onMouseOut = curriedOn "mouseout"
 | |
| onCheck = curriedOn "check"
 | |
| onBlur = curriedOn "blur"
 | |
| onFocus = curriedOn "focus"
 | |
| 
 | |
| onInput : List CyclicStructureAccessor, (state, List (List U8) -> Action state) -> Attribute state
 | |
| onInput = \accessors, callback ->
 | |
|     customCallback : state, List (List U8) -> { action : Action state, stopPropagation : Bool, preventDefault : Bool }
 | |
|     customCallback = \state, jsons -> {
 | |
|         action: callback state jsons,
 | |
|         stopPropagation: Bool.true,
 | |
|         preventDefault: Bool.false,
 | |
|     }
 | |
| 
 | |
|     EventListener "input" accessors (Custom customCallback)
 | |
| 
 | |
| onSubmit : List CyclicStructureAccessor, (state, List (List U8) -> Action state) -> Attribute state
 | |
| onSubmit = \accessors, callback ->
 | |
|     customCallback = \state, jsons -> {
 | |
|         action: callback state jsons,
 | |
|         stopPropagation: Bool.false,
 | |
|         preventDefault: Bool.true,
 | |
|     }
 | |
| 
 | |
|     EventListener "submit" accessors (Custom customCallback)
 | |
| 
 | |
| # Notes from Elm:
 | |
| #  - stopPropagation causes immediate view update, without waiting for animationFrame,
 | |
| #       to prevent input state getting out of sync with model state when typing fast.
 | |
| #  - Security-sensitive events trigger an immediate update within the same user-instigated tick
 |