<commit_before>var Firebase = require('firebase');
var clone = require('clone');

var config = require('../config');
var utils = require('./utils');
var i18n = require('./i18n');
var templates = require('./templates.json');
var model = require('./model')();
var Blocks = require('./blocks');
var blocks = new Blocks();

var _firebase = new Firebase(config.FIREBASE_URL + '/apps');
var _appRefs = {};
var _queryRef = null;

function Store(vm) {
    var self = this;

    self._vm = vm;
    self._firebase = _firebase;
}

Store.prototype._log = function (text) {
    console.log('[Store] ', text);
};

Store.prototype._onSync = function _onSync(err) {
    var self = this;
    if (!err) return;
    console.error('[Store] ', err);
    self._vm.showAlert('Oops! We\'re having trouble syncing your data');
};

Store.prototype._processSnapshot = function _processSnapshot(snapshot) {
    var res = snapshot.val();
    if (!res) return null;
    res.id = snapshot.key();
    return res;
};

Store.prototype._createAppRef = function (id, fbRef, data) {
    if (_appRefs[id]) this._removeAppRef(id);

    var that = this;
    var process = that._processSnapshot;

    function newBlock(blockId) {
        var block = blocks[blockId];
        if (!block) return;
        var clonedBlock = clone(block);
        if (['text', 'phone', 'sms', 'submit'].indexOf(block.type) !== -1) {
            clonedBlock.attributes.innerHTML.value =
              i18n.get(clonedBlock.attributes.innerHTML.value);
        }
        return clonedBlock && clone(clonedBlock);
    }

    function App() {
        var self = this;

        function broadcast(snapshot) {
            var data = process(snapshot);
            self.data = data;
            that._vm.$broadcast(snapshot.key(), data);
        }

        self.id = id;
        self.data = data || null;
        self.firebase = fbRef || _firebase.child(id);
        self.firebase.on('value', broadcast);
    }

    App.prototype.update = function (properties) {
        var self = this;
        properties = JSON.parse(JSON.stringify(properties));
        self.firebase.update(properties, that._onSync);
    };

    App.prototype.updateBlock = function (id, properties) {
        var self = this;
        properties = JSON.parse(JSON.stringify(properties));<commit_msg>Fix comment<commit_after>var Firebase = require('firebase');
var clone = require('clone');

var config = require('../config');
var utils = require('./utils');
var i18n = require('./i18n');
var templates = require('./templates.json');
var model = require('./model')();
var Blocks = require('./blocks');
var blocks = new Blocks();

var _firebase = new Firebase(config.FIREBASE_URL + '/apps');
var _appRefs = {};
var _queryRef = null;

function Store(vm) {
    var self = this;

    self._vm = vm;
    self._firebase = _firebase;
}

Store.prototype._log = function (text) {
    console.log('[Store] ', text);
};

Store.prototype._onSync = function _onSync(err) {
    var self = this;
    if (!err) return;
    console.error('[Store] ', err);
    self._vm.showAlert('Oops! We\'re having trouble syncing your data');
};

Store.prototype._processSnapshot = function _processSnapshot(snapshot) {
    var res = snapshot.val();
    if (!res) return null;
    res.id = snapshot.key();
    return res;
};

Store.prototype._createAppRef = function (id, fbRef, data) {
    if (_appRefs[id]) this._removeAppRef(id);

    var that = this;
    var process = that._processSnapshot;

    function newBlock(blockId) {
        var block = blocks[blockId];
        if (!block) return;
        var clonedBlock = clone(block);
        if (['text', 'phone', 'sms', 'submit'].indexOf(block.type) !== -1) {
            clonedBlock.attributes.innerHTML.value =
              i18n.get(clonedBlock.attributes.innerHTML.value);
        }
        return clonedBlock;
    }

    function App() {
        var self = this;

        function broadcast(snapshot) {
            var data = process(snapshot);
            self.data = data;
            that._vm.$broadcast(snapshot.key(), data);
        }

        self.id = id;
        self.data = data || null;
        self.firebase = fbRef || _firebase.child(id);
        self.firebase.on('value', broadcast);
    }

    App.prototype.update = function (properties) {
        var self = this;
        properties = JSON.parse(JSON.stringify(properties));
        self.firebase.update(properties, that._onSync);
    };

    App.prototype.updateBlock = function (id, properties) {
        var self = this;
        properties = JSON.parse(JSON.stringify(properties));
{'fraction_non_alphanumeric': 0.14903846153846154, 'fraction_numerical': 0.0030594405594405595, 'mean_word_length': 2.7826446280991735, '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': '4067449', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1363, 'n_words': 325}