Last active
March 18, 2020 16:07
-
-
Save matthewstokeley/0870dd71135729339649b5dc4d71aaf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*> Click Handler Middleware */ | |
// @version 0.0.3 | |
// CHANGELOG | |
// 0.0.3 add type scaffolding | |
type Next = function():void {} | |
interface Target { | |
tagName: String | |
} | |
interface Event { | |
target: Target | |
} | |
function layeredEventTargetEventPropagation( | |
event: Event, next: Next ) { | |
if event.target.tagName === 'SPAN' | |
event.preventDefault() | |
if event.target.tagName === 'A' | |
event.preventDefault(); | |
event.stopPropagation() | |
next() | |
} | |
const middleware_substack = [ | |
'layeredEventTargetEventPropagation' | |
] | |
function clickHandler( event ) {} | |
function clickHandlerFacade( | |
event: Object, | |
middleware_substack: Array<Function>, | |
clickHandler: Function | |
) { | |
if ( clickHandler ) | |
middleware_substack.push( clickHandler ) | |
this.event = event ?? {} | |
let i = 0 | |
const next = function next() { | |
if ( i < middlware_substack.length ) { | |
middleware_substack[ i ].call( this, this.event, next ) | |
i++ | |
} | |
} | |
middleware_substack[ middleware_substack.length ].call( this, this.event, next ) | |
} |
Author
matthewstokeley
commented
Mar 18, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment