Skip to content

Commit

Permalink
Make PromiseMonitor call reporter.configurePromiseMonitor if availabl…
Browse files Browse the repository at this point in the history
…e. See #270
  • Loading branch information
briancavalier committed Apr 4, 2014
1 parent 1f8a931 commit f57fe4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 9 additions & 5 deletions monitor/PromiseMonitor.js
Expand Up @@ -12,7 +12,7 @@ define(function(require) {
var error = require('./error');

function PromiseMonitor(reporter) {
this.traces = {};
this._traces = {};
this.traceTask = 0;
this.logDelay = 100;
this.stackFilter = defaultStackFilter;
Expand All @@ -21,6 +21,10 @@ define(function(require) {

this._reporter = reporter;

if(typeof reporter.configurePromiseMonitor === 'function') {
reporter.configurePromiseMonitor(this);
}

var self = this;
this._doLogTraces = function() {
self._logTraces();
Expand All @@ -32,7 +36,7 @@ define(function(require) {
};

PromiseMonitor.prototype.addTrace = function(handler, extraContext) {
this.traces[handler.id] = {
this._traces[handler.id] = {
error: handler.value,
context: handler.context,
extraContext: extraContext
Expand All @@ -41,8 +45,8 @@ define(function(require) {
};

PromiseMonitor.prototype.removeTrace = function(handler) {
if(handler.id in this.traces) {
delete this.traces[handler.id];
if(handler.id in this._traces) {
delete this._traces[handler.id];
this.logTraces();
}
};
Expand All @@ -63,7 +67,7 @@ define(function(require) {

PromiseMonitor.prototype._logTraces = function() {
this.traceTask = void 0;
this._reporter.log(this.formatTraces(this.traces));
this._reporter.log(this.formatTraces(this._traces));
};


Expand Down
9 changes: 9 additions & 0 deletions test/monitor/PromiseMonitor-test.js
Expand Up @@ -44,6 +44,15 @@ define('when/monitor/PromiseMonitor-test', function (require) {
}});

Promise.reject();
},

'should call reporter.configurePromiseMonitor with self': function() {
var spy = this.spy();
var m = new PromiseMonitor({
configurePromiseMonitor: spy
});

assert.calledOnceWith(spy, m);
}
});

Expand Down

0 comments on commit f57fe4d

Please sign in to comment.