Created
June 23, 2017 19:55
-
-
Save hardboiled/9a0665d3d66c8af9231f7adde329ab57 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
//usage of interface | |
clientInterfaceInstance.trigger('window-focus', screen.width, screen.height) | |
//definitions | |
class ClientInterface { | |
initialize(client) { | |
this.client = client; | |
} | |
//public function | |
trigger(event) { | |
argsFromEvent = Array.prototype.slice.call(arguments, 1) | |
functionName = this.convertEventToCamelCase(event) | |
if (this.client[event] && (typeof this.client[event] === 'function')) { | |
this.client[event].apply(this, argsFromEvent); | |
} else { | |
//nothing happens, since an event wasn't mapped to a function name. | |
} | |
} | |
//private functions | |
convertEventToCamelCase(event) { | |
event.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); }); | |
} | |
} | |
class BaseClient { | |
someUXinteraction(e) { | |
//common code here | |
} | |
} | |
class AndroidClient extends BaseClient { | |
windowFocus(width, height) { | |
//define android specific code here | |
} | |
} | |
class IosClient extends BaseClient { | |
windowFocus(width, height) { | |
//define android specific code here | |
} | |
} | |
class WebClient extends BaseClient { | |
//doesn't need windowFocus, so leave undefined | |
someUXinteraction(e) { | |
//add Web specific code here, since it needs extra animations based off browser type | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment