Created
April 17, 2013 19:42
-
-
Save meeech/5407137 to your computer and use it in GitHub Desktop.
Test using Ti.App events vs using JS only event system.
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
var win = Ti.UI.createWindow({backgroundColor: '#fff'}) | |
, Emitter = require('emitter') //https://github.com/component/emitter | |
, event = new Emitter() | |
, limit = 10000 | |
, i = 0 | |
, startTime | |
; | |
var buttonTi = Ti.UI.createButton({title: 'start-Ti', left: 10}); | |
var buttonJs = Ti.UI.createButton({title: 'start-js', right: 10}); | |
win.add(buttonTi); | |
win.add(buttonJs); | |
win.open(); | |
var start = function(){ | |
console.log('->Starting'); | |
i = 0; | |
startTime = new Date(); | |
}; | |
var stop = function() { | |
var now = new Date(); | |
console.log(now - startTime, 'ms'); | |
}; | |
var eventData = {data: "to pass", to: "listener" }; | |
buttonTi.addEventListener('click', function() { | |
start(); | |
Ti.App.fireEvent('app:custom', eventData); | |
}); | |
buttonJs.addEventListener('click', function() { | |
start(); | |
event.emit('app:custom', eventData ); | |
}); | |
Ti.App.addEventListener('app:custom', function(e) { | |
i++; | |
if(i < limit) { | |
Ti.App.fireEvent('app:custom', eventData); | |
} | |
else { | |
console.log('->Stopping Ti'); | |
stop(); | |
} | |
}); | |
event.on('app:custom', function(e) { | |
i++; | |
if(i < limit) { | |
event.emit('app:custom', eventData); | |
} | |
else { | |
console.log('->Stopping Js'); | |
stop(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment