Skip to content
This repository has been archived by the owner on May 24, 2018. It is now read-only.

Commit

Permalink
Fixed compare builders issue(the real time functions call order doesn…
Browse files Browse the repository at this point in the history
…'t depend on instant JSON elements order)
  • Loading branch information
Kateryna Musina committed Jun 9, 2016
1 parent 205a1ea commit 06288fa
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
30 changes: 15 additions & 15 deletions www/prod/script/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion www/prod/script/main.js.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions www/script/project/realtimePages.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,25 @@ define(function (require) {
},
updateRealTimeData: function (json, instantJSON) {
if (instantJSON === true) {
var realTimeFuncData = {}
$.each(json, function (name, jObj) {
var data = jObj.data;
if (typeof data === "string") {
data = JSON.parse(data);
realtimeURLs[name] = jObj.url;
}

if (realTimeFunctions.hasOwnProperty(name)) {
realTimeFuncData[name] = data;
return true;
}
realtimePages.updateSingleRealTimeData(name, data);
});

// Real time functions should be called preserving their order in the list, should not depend on instantJson elements order
$.each(Object.keys(realTimeFunctions), function(i, name){
realtimePages.updateSingleRealTimeData(name, realTimeFuncData[name]);
});
} else {
var name = realtimePages.getRealtimeNameFromURL(json.url);
realtimePages.updateSingleRealTimeData(name, json.data);
Expand Down
25 changes: 25 additions & 0 deletions www/script/test/test_realTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ define(["jquery", "realtimePages", "rtGlobal"], function ($, rt, rtGlobal) {
rt.getInstantJSON();
expect($("#instant-json").length).toEqual(0);
});

it("elements order doesn't define realtime functions call order(preserve the order of real time functions call)", function () {
var callsLog = []
var realtimeFunctionsList = {
example: function () {
return callsLog.push("example");
},
codebases: function () {
return callsLog.push("codebases");
},
builder0: function () {
return callsLog.push("builder0");
},
builder1: function () {
return callsLog.push("builder1");
}
},
realtimeDataList = {data: {"cmd": "krtJSONData", "data": {"url": "http://test.com", "data": {"builder0":["builder0"], "builder1":["builder1"], "codebases":["codebases"], "example": ["example"]}}}};

rt.setReloadCooldown(5000);

rt.initRealtime(realtimeFunctionsList);
rt.updateRealTimeData(realtimeDataList.data.data.data, true);
expect(Object.keys(realtimeFunctionsList)).toEqual(callsLog);
});
});

describe("A websocket", function () {
Expand Down

0 comments on commit 06288fa

Please sign in to comment.