Skip to content

Instantly share code, notes, and snippets.

@partlyhuman
Created November 14, 2013 23:42
Show Gist options
  • Save partlyhuman/7476458 to your computer and use it in GitHub Desktop.
Save partlyhuman/7476458 to your computer and use it in GitHub Desktop.
Seed of a local testing harness for quick iteration of PebbleJS apps. Could add to this providing a way to simulate appmessages, etc.
var Pebble = new (function(){
var dispatchTable = {};
this.addEventListener = function(eventName, delegate) {
if (!(eventName in dispatchTable)) dispatchTable[eventName] = [];
dispatchTable[eventName].push(delegate);
}
this.dispatchEvent = function(event) {
var listeners = dispatchTable[event.type] || [];
for (var i = 0; i < listeners.length; i++) {
listeners[i].call(this, event);
}
}
this.sendAppMessage = function(obj) {
console.log("Fake sending app message:");
console.dir(obj);
}
})();
// Simulate pebble app load on page load
document.addEventListener("readystatechange", function(event) {
if (document.readyState == "complete") {
var consoleOriginal = console;
var domLog = document.getElementById("log");
console.log = function(m) {
domLog.innerText += "LOG: " + m + "\n";
}
console.warn = function(m) {
domLog.innerText += "WARN: " + m + "\n";
}
console.error = function(m) {
domLog.innerText += "ERROR: " + m + "\n";
}
Pebble.dispatchEvent(new Event("ready"));
}
});
<html>
<head>
<title>Pebble local JS app tester</title>
<script src="pebble-jsapi-local.js"></script>
<script src="../src/js/pebble-js-app.js"></script>
</head>
<body>
<pre id="log"></pre>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment