Bug 1023020 - Add a "ready" promise to canvas graphs, r=pbrosset

This commit is contained in:
Victor Porof 2014-06-10 10:55:32 -04:00
Родитель 1bf902d8ce
Коммит 6144e90848
2 изменённых файлов: 17 добавлений и 2 удалений

Просмотреть файл

@ -20,7 +20,12 @@ function* performTest() {
doc.body.setAttribute("style", "position: fixed; width: 100%; height: 100%; margin: 0;"); doc.body.setAttribute("style", "position: fixed; width: 100%; height: 100%; margin: 0;");
let graph = new LineGraphWidget(doc.body, "fps"); let graph = new LineGraphWidget(doc.body, "fps");
yield graph.once("ready");
let readyEventEmitted;
graph.once("ready", () => readyEventEmitted = true);
yield graph.ready();
ok(readyEventEmitted, "The 'ready' event should have been emitted");
testGraph(host, graph); testGraph(host, graph);

Просмотреть файл

@ -5,8 +5,9 @@
const Cu = Components.utils; const Cu = Components.utils;
Cu.import("resource://gre/modules/devtools/event-emitter.js");
Cu.import("resource:///modules/devtools/ViewHelpers.jsm"); Cu.import("resource:///modules/devtools/ViewHelpers.jsm");
const promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise;
const {EventEmitter} = Cu.import("resource://gre/modules/devtools/event-emitter.js", {});
this.EXPORTED_SYMBOLS = ["LineGraphWidget"]; this.EXPORTED_SYMBOLS = ["LineGraphWidget"];
@ -116,6 +117,7 @@ GraphSelectionResizer.prototype = {
this.AbstractCanvasGraph = function(parent, name, sharpness) { this.AbstractCanvasGraph = function(parent, name, sharpness) {
EventEmitter.decorate(this); EventEmitter.decorate(this);
this._ready = promise.defer();
this._parent = parent; this._parent = parent;
this._uid = "canvas-graph-" + Date.now(); this._uid = "canvas-graph-" + Date.now();
@ -165,6 +167,7 @@ this.AbstractCanvasGraph = function(parent, name, sharpness) {
this._animationId = this._window.requestAnimationFrame(this._onAnimationFrame); this._animationId = this._window.requestAnimationFrame(this._onAnimationFrame);
this._ready.resolve(this);
this.emit("ready", this); this.emit("ready", this);
}); });
} }
@ -181,6 +184,13 @@ AbstractCanvasGraph.prototype = {
return this._height; return this._height;
}, },
/**
* Returns a promise resolved once this graph is ready to receive data.
*/
ready: function() {
return this._ready.promise;
},
/** /**
* Destroys this graph. * Destroys this graph.
*/ */