Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pik committed Jan 20, 2017
1 parent 501b949 commit b80e207
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
5 changes: 2 additions & 3 deletions spec/mock-request.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"use strict";
const q = require("q");
let clock = jasmine.Clock;
let fakeDate;
let callbacks = require("../lib/realtime-callbacks");

let tick = function tick(millis) {
// make sure we tick the fakedate first, otherwise nothing will happen!
fakeDate += millis;
clock.tick(millis);
jasmine.Clock.tick(millis);
};


Expand Down Expand Up @@ -59,7 +58,7 @@ HttpBackend.prototype = {
);
// Mock out Clock for .timeout() tests
if (this.useMockClock) {
clock.useMock();
jasmine.Clock.useMock();
fakeDate = Date.now();
callbacks.setNow(function() {
return fakeDate;
Expand Down
5 changes: 2 additions & 3 deletions spec/unit/http-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ const TimeoutContext = HttpApi.__TimeoutContext;

describe("Http-Api", function() {
describe("TimeoutContext", function() {
const clock = jasmine.Clock;
let fakeDate;

function tick(millis) {
// make sure we tick the fakedate first, otherwise nothing will happen!
fakeDate += millis;
clock.tick(millis);
jasmine.Clock.tick(millis);
}

beforeEach(function() {
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
clock.useMock();
jasmine.Clock.useMock();
fakeDate = Date.now();
callbacks.setNow(function() {
return fakeDate;
Expand Down
5 changes: 2 additions & 3 deletions src/http-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const TimeoutContext = function TimeoutContext(timeoutFunction, waitMs) {
module.exports.__TimeoutContext = TimeoutContext;

TimeoutContext.prototype.onProgressCheck = function(progressEvent) {
if (this.lastLoaded || progressEvent.loaded > this.lastLoaded) {
if (this.lastLoaded === null || progressEvent.loaded > this.lastLoaded) {
callbacks.debounce(this.jobName);
this.lastLoaded = progressEvent.loaded;
}
Expand Down Expand Up @@ -703,7 +703,6 @@ module.exports.MatrixHttpApi.prototype = {
function(err, response, body) {
if (timeoutContext) {
timeoutContext.stop();
delete req.onprogres;
if (timedOut) {
return; // already rejected promise
}
Expand All @@ -721,7 +720,7 @@ module.exports.MatrixHttpApi.prototype = {
}
);
if (timeoutContext) {
req.onprogress = timeoutContext.onProgressCheck;
req.onprogress = timeoutContext.onProgressCheck.bind(this);
timeoutContext.start();
}
if (req && req.abort) {
Expand Down
2 changes: 1 addition & 1 deletion src/realtime-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Debouncer {

start(func, waitMs) {
if (func) this.func = func;
if (!isNaN(waitMs)) this.waitMs = waitMs;
if (waitMs > 0) this.waitMs = waitMs;
this.timeoutId = exports.setTimeout(this.complete.bind(this), this.waitMs);
}

Expand Down

0 comments on commit b80e207

Please sign in to comment.