<commit_before>(function() {
    var connected = new Promise();

    Backbone.io = Backbone.IO = {
        connect: function() {
            var socket = io.connect.apply(io, arguments);
            connected.resolve(socket);
            return socket;
        }
    };
    
    var origSync = Backbone.sync;

    Backbone.sync = function(method, model, options) {
        var backend = model.backend || (model.collection && model.collection.backend);
        
        options = _.clone(options);

        var error = options.error || function() {};
        var success = options.success || function() {};
        
        if (backend) {
            // Don't pass the callbacks to the backend
            delete options.error;
            delete options.success;
            
            // Use Socket.IO backend
            backend.ready(function() {
                var req = {
                    method: method,
                    model: model.toJSON(),
                    options: options
                };
                
                backend.socket.emit('sync', req, function(err, resp) {
                    if (err) {
                        error(err);
                    } else {
                        success(resp);
                    }
                });
            });
        } else {
            // Call the original Backbone.sync
            return origSync(method, model, options);
        }
    };<commit_msg>Update lib/browser.js<commit_after>(function() {
    var connected = new Promise();

    Backbone.io = Backbone.IO = {
        connect: function() {
            var socket = io.connect.apply(io, arguments);
            connected.resolve(socket);
            return socket;
        }
    };
    
    var origSync = Backbone.sync;

    Backbone.sync = function(method, model, options) {
        var backend = model.backend || (model.collection && model.collection.backend);
        
        options = _.clone(options);

        var error = options.error || function() {};
        var success = options.success || function() {};
        
        if (backend) {
            // Don't pass the callbacks to the backend
            delete options.error;
            delete options.success;
            
            // Use Socket.IO backend
            backend.ready(function() {
                var req = {
                    method: method,
                    model: model.toJSON(),
                    options: options
                };
                
                backend.socket.emit('sync', req, function(err, resp) {
                    if (err) {
                        error(model, err, options);
                    } else {
                        success(model, resp, options);
                    }
                });
            });
        } else {
            // Call the original Backbone.sync
            return origSync(method, model, options);
        }
    };
{'fraction_non_alphanumeric': 0.10609171800136892, 'fraction_numerical': 0.0, 'mean_word_length': 1.1846038863976083, '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': '55363', 'n_tokens_mistral': 702, 'n_tokens_neox': 669, 'n_words': 167}