Skip to content

Instantly share code, notes, and snippets.

@matthewstokeley
Last active March 16, 2020 18:39
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/2dbf8a89166fc52360199f86c6a51fbc to your computer and use it in GitHub Desktop.
Save matthewstokeley/2dbf8a89166fc52360199f86c6a51fbc to your computer and use it in GitHub Desktop.
an on-one-off robust api with the mixin pattern
// dom versus publisher subscribe naming conventions
const Handler = ( function() {
return {}
} )()
type eventName: String
type eventFn: Function
let on = function(
name: eventName,
fn: eventFn
) {
}
let one = function(
name: eventName,
fn: eventFn
) {
}
let off = function(
name: eventName,
fn: eventFn
) {
}
let eventMixins = {
on,
one,
off
}
const mixin = function( source, target ) {
for ( let prop of source ) {
if ( source.hasOwnProperty( prop ) {
if ( prop in target ) {
}
// poor man's object mutator
target.prototype[ prop ] = source[ prop ]
}
}
}
describe( 'Handler', () => {
it( 'should trigger a callback', () => {
} )
} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment