Last active
March 16, 2020 18:39
-
-
Save matthewstokeley/2dbf8a89166fc52360199f86c6a51fbc to your computer and use it in GitHub Desktop.
an on-one-off robust api with the mixin pattern
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
// 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