<commit_before>const CHANNEL_DELAY = 1500;

class ChannelAPI {
  constructor(registry) {
    var currentUserStore = registry.getStore('currentUser');
    var channel = null;
    var channelToken = null;

    this.registry = registry;

    currentUserStore.on('change', () => {
      var currentChannelToken = currentUserStore.state.channelToken;
      if (currentChannelToken === null || 
          currentChannelToken === channelToken) {
        return;
      }

      console.log(
        'ChannelAPI: have a channel token!', 
        currentChannelToken
      );

      // XXX For some reason the channel API doesn't work if we call it right 
      // after load here, and not with a setTimeout delay. Who knows why?
      setTimeout(() => {
        channelToken = currentChannelToken;
        channel = new goog.appengine.Channel(channelToken);
        channel.open({
          onopen: () => console.log('ChannelAPI: opened.'),
          onerror: () => console.log('ChannelAPI: opened.'),
          onmessage: this.handleMessage.bind(this),
          onclose: this.handleClosed.bind(this)
        });
      }, CHANNEL_DELAY);
    });
  }

  handleMessage(message) {
    var msg = JSON.parse(message.data);
    
    var agendaActions = this.registry.getActions('agenda');<commit_msg>Start dumping data about how long it takes to set up a Channel.<commit_after>const CHANNEL_DELAY = 1500;

class ChannelAPI {
  constructor(registry) {
    var currentUserStore = registry.getStore('currentUser');
    var channel = null;
    var channelToken = null;

    this.registry = registry;

    currentUserStore.on('change', () => {
      var currentChannelToken = currentUserStore.state.channelToken;
      if (currentChannelToken === null || 
          currentChannelToken === channelToken) {
        return;
      }

      console.log(
        'ChannelAPI: have a channel token!', 
        currentChannelToken
      );

      // XXX For some reason the channel API doesn't work if we call it right 
      // after load here, and not with a setTimeout delay. Who knows why?
      var connect = () => {
        this.initialNow = +Date.now();

        channelToken = currentChannelToken;
        channel = new goog.appengine.Channel(channelToken);
        channel.open({
          onopen: this.handleOpened.bind(this),
          onerror: () => console.log('ChannelAPI: opened.'),
          onmessage: this.handleMessage.bind(this),
          onclose: this.handleClosed.bind(this)
        });
      };

      setTimeout(connect, CHANNEL_DELAY);
    });
  }

  handleOpened() {
    console.log('ChannelAPI: opened after ', +Date.now() - this.initialNow);
  }

  handleMessage(message) {
    var msg = JSON.parse(message.data);
    
    var agendaActions = this.registry.getActions('agenda');
{'fraction_non_alphanumeric': 0.1147069399496584, 'fraction_numerical': 0.002876663070837828, 'mean_word_length': 2.608300907911803, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '1336052', 'n_tokens_mistral': 782, 'n_tokens_neox': 749, 'n_words': 190}