Created
September 14, 2010 15:26
-
-
Save kwhinnery/579206 to your computer and use it in GitHub Desktop.
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
var listeners = []; | |
api.pub = function(name,data) { | |
//first, check to see if we have a regex listener and call it if we do | |
for (var i = 0;i < listeners.length;i++) { | |
var listener = listeners[i]; | |
if (listener.regex.test(name)) { | |
listener.fn.call(this,data); | |
} | |
} | |
//then, pass through to standard Titanium event handling | |
Ti.App.fireEvent(name,data||{}); | |
}; | |
api.sub = function(nameOrRegex,fn) { | |
//string indicated plain old subscribe | |
if (typeof(nameOrRegex) == 'string') { | |
Ti.App.addEventListener(nameOrRegex,fn); | |
} | |
else { | |
//assume we have a regular expression and add it to listeners | |
listeners.push({ | |
regex:nameOrRegex, | |
fn:fn | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment