<commit_before>var path = require('path');
var express = require('express');
var socketio = require('socketio');
var browserify = require('browserify');

var SCRIPT_NAME = 'client.js';
var RECOMPILE_ALWAYS = true;

function Mount(Page, registerExpressCustom) {
    this._id = 0;
    this.register = new Map();
    this.Page = Page;
    this.app = express();
    if (registerExpressCustom) {
        registerExpressCustom(this.app);
    }
}

Mount.prototype.listen = function(port, cb) {
    var server;
    this.registerExpress();
    server = this.app.listen(port || 3000, cb || function () {
        var address = server.address();
        console.log('listening on http://*:' + address.port + '/');
    });
    this.io = socketio.listen(server);
    this.io.on('connection', this.handleSocketConnection.bind(this);
}

Mount.prototype.registerExpress = function() {
    this.app.get('/virtual-dom-server.js', this.sendJavascript.bind(this));
    this.app.all('*', this.handleHttpConnection.bind(this));
};

Mount.prototype.handleHttpConnection = function(req, res) {
    var connid, page;
    res.set('Content-Type', 'text/html');
    connid = this.generateConnectionId();
    page = new this.Page();
};

Mount.prototype.handleSocketConnection = function(socket) {
};


Mount.prototype.sendJavascript = function(res) {
    res.set('Content-Type', 'text/javascript');
    if (this._script === undefined || RECOMPILE_ALWAYS) {
        compileJavascript(SCRIPT_NAME, function (script) {
            this._script = script;
            res.send(script);
        }, this);
    } else {
        res.send(this._script);
    }
};

Mount.prototype.generateConnectionId = function () {
    return this._id++;
};

module.exports = function (port, PageClass, cb) {
    var mount;
    mount = new Mount(PageClass);
    mount.listen(port, cb);
}

function compileJavascript(filename, cb, bindTo) {
    var bundle;
    bundle = browserify(path.join(__dirname, filename)).bundle();
    streamToString(bundle, cb.bind(bindTo));
}

function streamToString (stream, cb) {
    var result = '';
    stream.on('data', function (buffer) {
        result += buffer.toString();
    });
    stream.on('end', function () {
        cb(result);
    });
}

function pageToHtml(page) {
    return (
        '<!doctype html>' +
        '<html>' +
            '<head>' +
                '<script src="/socket.io/socket.io.js"></script>' +
                (page.head || []).join('')
            '</head>' +
            '<body>' +
                '<script src="virtual-dom-remote-mount.js"></script>' +
                '<div id="virtual-dom-remote-mount-target">' +
                    page.initialHtml() +
                '/<div>' +
            '</body>' +
        '</html>'
    );
}<commit_msg>fix errors<commit_after>var path = require('path');
var express = require('express');
var socketio = require('socket.io');
var browserify = require('browserify');

var SCRIPT_NAME = 'client.js';
var RECOMPILE_ALWAYS = true;

function Mount(Page, registerExpressCustom) {
    this._id = 0;
    this.register = new Map();
    this.Page = Page;
    this.app = express();
    if (registerExpressCustom) {
        registerExpressCustom(this.app);
    }
}

Mount.prototype.listen = function(port, cb) {
    var server;
    this.registerExpress();
    server = this.app.listen(port || 3000, cb || function () {
        var address = server.address();
        console.log('listening on http://*:' + address.port + '/');
    });
    this.io = socketio.listen(server);
    this.io.on('connection', this.handleSocketConnection.bind(this));
}

Mount.prototype.registerExpress = function() {
    this.app.get('/virtual-dom-server.js', this.sendJavascript.bind(this));
    this.app.use('/', this.handleHttpConnection.bind(this));
};

Mount.prototype.handleHttpConnection = function(req, res) {
    var connid, page;
    res.set('Content-Type', 'text/html');
    connid = this.generateConnectionId();
    page = new this.Page();
    res.send(pageToHtml(page));
};

Mount.prototype.handleSocketConnection = function(socket) {
};


Mount.prototype.sendJavascript = function(res) {
    res.set('Content-Type', 'text/javascript');
    if (this._script === undefined || RECOMPILE_ALWAYS) {
        compileJavascript(SCRIPT_NAME, function (script) {
            this._script = script;
            res.send(script);
        }, this);
    } else {
        res.send(this._script);
    }
};

Mount.prototype.generateConnectionId = function () {
    return this._id++;
};

module.exports = function (port, PageClass, cb) {
    var mount;
    mount = new Mount(PageClass);
    mount.listen(port, cb);
}

function compileJavascript(filename, cb, bindTo) {
    var bundle;
    bundle = browserify(path.join(__dirname, filename)).bundle();
    streamToString(bundle, cb.bind(bindTo));
}

function streamToString (stream, cb) {
    var result = '';
    stream.on('data', function (buffer) {
        result += buffer.toString();
    });
    stream.on('end', function () {
        cb(result);
    });
}

function pageToHtml(page) {
    return (
        '<!doctype html>' +
        '<html>' +
            '<head>' +
                '<script src="/socket.io/socket.io.js"></script>' +
                (page.head || []).join('') +
            '</head>' +
            '<body>' +
                '<script src="virtual-dom-remote-mount.js"></script>' +
                '<div id="virtual-dom-remote-mount-target">' +
                    page.initialHtml() +
                '/<div>' +
            '</body>' +
        '</html>'
    );
}
{'fraction_non_alphanumeric': 0.1686161597984524, 'fraction_numerical': 0.0017995321216483715, 'mean_word_length': 2.688122096881221, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '3922428', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1675, 'n_words': 312}