Skip to content

Instantly share code, notes, and snippets.

@matthewstokeley
Last active March 18, 2020 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewstokeley/0870dd71135729339649b5dc4d71aaf4 to your computer and use it in GitHub Desktop.
Save matthewstokeley/0870dd71135729339649b5dc4d71aaf4 to your computer and use it in GitHub Desktop.
/*> 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 )
}
@matthewstokeley
Copy link
Author

matthewstokeley commented Mar 18, 2020

import { debounce } from 'lo'
const facade = () => {
    return {
       throttle: debounce,
       raf: window.requestAnimationFrame
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment