<commit_before>// if node
var util = require('./util.js');

var CallQueue = require('./callqueue.js');
var NowConnection = require('./web.js').NowConnection;
var NowSerialize = require('./nowserialize.js');
var NowPath = require('./nowpath.js');
// end node


function Now(options) {
  var self = this;
  this.children = {};
  this.callQueue = new CallQueue(this);
  // Communication layer
  this.connection = new NowConnection(function(){
    util.info('Connected');
    // Start processing queue
    self.callQueue.process();
  }, this.onMessage.bind(this), options); 
};

Now.prototype.getPathObj = function(pathchain, named) {
  return new NowPath(this, pathchain, named);
}

Now.prototype.getRootRef = function() {
  return new NowPath(this, [this.connection.clientId], false);
}

Now.prototype.onMessage = function(message) {
  util.info('Message received: ', message, typeof(message));
  var pathchain = message.pathchain;
  if (!pathchain) {
    util.warn('NO PATHCHAIN IN MESSAGE, IGNORING');
    return;
  }

  // Add client Id so execute() treats the call as local
  if ((pathchain[0] != this.getClientId()) && (pathchain[0] != 'local')) {
    pathchain.unshift(this.getClientId());
  }
  
  var args = NowSerialize.unserialize( this, ["list", message.args] );
  
  var ref = new NowPath(this, pathchain);
  ref.call.apply(null, args);
};

Now.prototype.getClientId = function() {
  return this.connection.clientId;
};

Now.prototype.executeLocal = function(pathchain, args) {
  var self = this;
  if (pathchain.length == 1) {
    if(util.hasProp(this.children, pathchain[0])) {
      // Have a reference for
      pathchain.push('default');
    } else {
      // Call on default handler
      pathchain.unshift('default');
    }
  } else if (pathchain.length == 0) {<commit_msg>receiving messages again<commit_after>// if node
var util = require('./util.js');

var CallQueue = require('./callqueue.js');
var NowConnection = require('./web.js').NowConnection;
var NowSerialize = require('./nowserialize.js');
var NowPath = require('./nowpath.js');
// end node


function Now(options) {
  var self = this;
  this.children = {};
  this.callQueue = new CallQueue(this);
  // Communication layer
  this.connection = new NowConnection(function(){
    util.info('Connected');
    // Start processing queue
    self.callQueue.process();
  }, this.onMessage.bind(this), options); 
};

Now.prototype.getPathObj = function(pathchain, named) {
  return new NowPath(this, pathchain, named);
}

Now.prototype.getRootRef = function() {
  return new NowPath(this, [this.connection.clientId], false);
}

Now.prototype.onMessage = function(message) {
  util.info('Message received: ', message, typeof(message));
  var unser = NowSerialize.unserialize(this, message);

  var destination = unser.destination;
  if (!destination) {
    util.warn('NO DESTINATION IN MESSAGE, IGNORING');
    return;
  }

  var pathchain = unser.destination.pathchain;
  var args = unser.args;

  // Add client Id so execute() treats the call as local
  if ((pathchain[0] != this.getClientId()) && (pathchain[0] != 'local')) {
    pathchain.unshift(this.getClientId());
  }
    
  var ref = new NowPath(this, pathchain);
  ref.call.apply(null, args);
};

Now.prototype.getClientId = function() {
  return this.connection.clientId;
};

Now.prototype.executeLocal = function(pathchain, args) {
  var self = this;
  if (pathchain.length == 1) {
    if(util.hasProp(this.children, pathchain[0])) {
      // Have a reference for
      pathchain.push('default');
    } else {
      // Call on default handler
      pathchain.unshift('default');
    }
  } else if (pathchain.length == 0) {
{'fraction_non_alphanumeric': 0.15517241379310345, 'fraction_numerical': 0.002736726874657909, 'mean_word_length': 3.7903014416775886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4960274', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1143, 'n_words': 270}