Created
July 25, 2012 16:28
-
-
Save jmarnold/3177082 to your computer and use it in GitHub Desktop.
Device Compatibility Spike
This file contains hidden or 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
class CompatibilityNotification | |
constructor: -> | |
@violations = [] | |
@rules = [] | |
registerRule: (rule) -> | |
# probably just need the key here | |
@rules.push(rule) | |
registerViolation: (key, message) -> | |
@violations.push(new CompatibilityViolation(key, message)) | |
# makes all the codez easier | |
class DeviceContext | |
isDefined: (obj, key) -> | |
return typeof(obj[key]) isnt 'undefined' | |
windowDefines: (key) -> | |
return @isDefined(window, key) | |
class CompatibilityViolation | |
constructor: (@key, @message) -> | |
class CompatibilityRunner | |
constructor: (@context, @rules) -> | |
run: -> | |
notification = new CompatibilityNotification() | |
for rule in @rules | |
notification.registerRule(rule) | |
rule.execute(@context, notification) | |
return notification | |
class WindowKeyCompatibilityRule | |
constructor: (@key, @message) -> | |
execute: (context, notification) -> | |
if(!context.windowDefines(@key)) | |
notification.registerViolation(@key, @message) | |
class ServerSentEventsRule extends WindowKeyCompatibilityRule | |
constructor: (@message = 'Server Sent events are not available') -> | |
@EventSourceKey = 'EventSource' | |
super @EventSourceKey, @message | |
class SomethingWeird extends WindowKeyCompatibilityRule | |
constructor: (@message = 'Something is not available') -> | |
@TheKey = 'Something' | |
super @TheKey, @message | |
class BasicBootstrapper | |
giveMeSomethingGood: -> | |
rules = [] | |
rules.push(new ServerSentEventsRule()) | |
rules.push(new SomethingWeird()) | |
context = new DeviceContext() | |
return new CompatibilityRunner(context, rules) | |
# Rules we need: EventSource, WebWorker, Html5 elements (section, article, form inputs [email, date]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment