Skip to content

Commit

Permalink
added fastRender debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
arunoda committed Nov 23, 2014
1 parent 8b217f7 commit 7ddfdd4
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 28 deletions.
17 changes: 10 additions & 7 deletions lib/client/ddp_update.js
Expand Up @@ -2,8 +2,10 @@ var reconnecting = false;

var originalLivedataData = Meteor.connection._livedata_data;
Meteor.connection._livedata_data = function(msg) {
Log('DDP_RECIEVE', msg);

if(FastRender._blockDDP && !msg.frGen) {
FastRender.debugger.log('blocking incoming ddp', msg);
return;
};
// fast-render adds data manually while initializing
// But when the server sends actual data via DDP, it also tries to add
// Then we need to detect that and alter
Expand All @@ -27,6 +29,7 @@ Meteor.connection._livedata_data = function(msg) {
if(localCollection) {
var existingDoc = localCollection.findOne(id);
if(existingDoc) {
FastRender.debugger.log('re writing DDP for:', msg);
AddedToChanged(existingDoc, msg);
}
} else if(pendingStoreUpdates) {
Expand All @@ -39,6 +42,7 @@ Meteor.connection._livedata_data = function(msg) {
mergedDoc = ApplyDDP(mergedDoc, cachedMsg);
});

FastRender.debugger.log('re writing DDP for:', msg);
AddedToChanged(mergedDoc, msg);
}
}
Expand All @@ -53,7 +57,7 @@ Meteor.connection._livedata_data = function(msg) {
msg.subs.forEach(function(subId) {
var subscription = FastRender._subscriptionIdMap[subId];
if(subscription) {
Log('DELETING_SUBSCRIPTION', subscription, subId);
FastRender.debugger.log('actual subscription completed:', subscription, subId);
// we don't need to handle specially after this
delete FastRender._subscriptions[subscription];
delete FastRender._subscriptionIdMap[subId];
Expand All @@ -64,7 +68,7 @@ Meteor.connection._livedata_data = function(msg) {
// if all the subscriptions have been processed,
// there is no need to keep hijacking
if(EJSON.equals(FastRender._subscriptions, {})) {
Log('REVERTING_BACK_TO_ORIGINAL_DDP_HANDLING');
FastRender.debugger.log('fast rendering completed!');
FastRender._revertedBackToOriginal = true;
}
}
Expand All @@ -74,8 +78,6 @@ Meteor.connection._livedata_data = function(msg) {

var originalSend = Meteor.connection._send;
Meteor.connection._send = function(msg) {
Log("DDP_SEND", msg);

// if looking for connect again to the server, we must need to revert back to
// original to prevent some weird DDP issues
// normally it is already reverted, but user may added subscriptions
Expand All @@ -93,8 +95,9 @@ Meteor.connection._send = function(msg) {
msg.msg == 'sub' &&
FastRender._subscriptions[msg.name];

FastRender.debugger.log('new subscription:', msg.name);
if(canSendFakeReady) {
Log('FAKE_SUB_READY', msg.name);
FastRender.debugger.log('sending fake ready for sub:', msg.name);
FastRender.injectDdpMessage(self, {msg:"ready",subs:[msg.id], frGen: true});
// add the messageId to be handled later
FastRender._subscriptionIdMap[msg.id] = msg.name;
Expand Down
38 changes: 38 additions & 0 deletions lib/client/debugger.js
@@ -0,0 +1,38 @@
FastRender.debugger = {};
FastRender.debugger._logs = [];
FastRender.debugger.log = function function_name(message/*, args..*/) {
if(
typeof console != 'undefined' &&
typeof Meteor._localStorage != 'undefined' &&
Meteor._localStorage.getItem('__frlog') == "1")
{
FastRender.debugger._logs.push(arguments);
arguments[0] = "FR: " + arguments[0];
console.log.apply(console, arguments);
}
}

FastRender.debugger.enable = function() {
Meteor._localStorage.setItem('__frlog', "1");
location.reload();
};

FastRender.debugger.disable = function() {
Meteor._localStorage.removeItem('__frlog');
location.reload();
};

FastRender.debugger.getLogs = function() {
var stringifyLogs = JSON.stringify(FastRender.debugger._logs);
console.log(stringifyLogs);
};

FastRender.debugger.blockDDP = function() {
Meteor._localStorage.setItem('__frblockddp', "1");
location.reload();
};

FastRender.debugger.unblockDDP = function() {
Meteor._localStorage.removeItem('__frblockddp');
location.reload();
};
8 changes: 5 additions & 3 deletions lib/client/fast_render.js
@@ -1,14 +1,15 @@
FastRender = {};
FastRender.enabled = typeof __fast_render_config != 'undefined';
FastRender.Log = Log;
FastRender._dataReceived = false;
FastRender._revertedBackToOriginal = false;
FastRender._blockDDP = Meteor._localStorage.getItem('__frblockddp') != undefined;

// This allow us to apply DDP message even if Meteor block accepting messages
// When doing initial login, Meteor sends an login message
// Then it'll block the accpeting DDP messages from server
// This is the cure
FastRender.injectDdpMessage = function(conn, message) {
FastRender.debugger.log('injecting ddp message:', message);
var originalWait = conn._waitingForQuiescence;
conn._waitingForQuiescence = function() {return false};
conn._livedata_data(message);
Expand Down Expand Up @@ -36,11 +37,12 @@ FastRender.init = function(payload) {
msg: 'added',
collection: collName,
id: id,
fields: item
fields: item,
frGen: true
};

FastRender.injectDdpMessage(Meteor.connection, ddpMessage);
});
});
}
};
};
17 changes: 0 additions & 17 deletions lib/client/log.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.js
Expand Up @@ -64,8 +64,8 @@ function configure (api) {
], 'server');

api.addFiles([
'lib/client/log.js',
'lib/client/fast_render.js',
'lib/client/debugger.js',
'lib/client/ddp_update.js',
'lib/client/data_handler.js',
'lib/client/auth.js'
Expand Down
7 changes: 7 additions & 0 deletions todo.md
@@ -0,0 +1,7 @@
* use better version of updated without usign deepExtend
* remove client side IR stuff
* use DDP level document replacement
* simply add null subscriptions data to when getting them
* support with new IR to detect docs on the server
* move docs to github
* add tests in mini-mongo

0 comments on commit 7ddfdd4

Please sign in to comment.