Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Created September 14, 2010 15:26
Show Gist options
  • Save kwhinnery/579206 to your computer and use it in GitHub Desktop.
Save kwhinnery/579206 to your computer and use it in GitHub Desktop.
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