<commit_before>Cell.prototype.propagateMeta = function () {
  var metaCell = this.ensureMetaCell();
  var staleMetaCell;
  var sourceCells = this.getSourceCells();

  if (metaCell.cancelRefresh) {
    metaCell.cancelRefresh();
  }

  for (var i = sourceCells.length - 1; i >= 0; i--) {
    var cell = sourceCells[i].metaCell;
    if (!cell || !cell.value) {
      continue;
    }
    var metaValue = cell.value;
    if (metaValue.stale) {
      staleMetaCell = cell;
      break;
    }
  }

  metaCell.setValueAttr(!!staleMetaCell, 'stale');

  var refreshSlave = new Slave($m(this, 'propagateMeta'));

  if (staleMetaCell) {
    staleMetaCell.changedSlot.subscribeWithSlave(refreshSlave);
  } else {
    for (var j = sourceCells.length - 1; j >= 0; j--) {
      var cell = sourceCells[j].metaCell;
      if (!cell) {
        continue;
      }
      cell.changedSlot.subscribeWithSlave(refreshSlave);
    }
  }

  metaCell.cancelRefresh = function () {
    refreshSlave.die();
    for (var i = sourceCells.length - 1; i >= 0; i--) {
      var cell = sourceCells[i].metaCell;
      if (!cell) {
        continue;
      }
      cell.changedSlot.cleanup();
    }
  };
};

Cell.STANDARD_ERROR_MARK = {"this is error marker":true};

Cell.cacheResponse = function (cell) {
  var cachingCell = new Cell(function () {
    var newValue = cell.value;
    var self = this.self;
    var oldValue = self.value;
    if (newValue === undefined) {
      if (oldValue === undefined) {
        return oldValue;
      }
      newValue = oldValue;
      self.setMetaAttr('loading', true);
      return newValue;
    }
    self.setMetaAttr('loading', false);
    if (newValue === Cell.STANDARD_ERROR_MARK) {
      newValue = oldValue;
      self.setMetaAttr('stale', true);
    } else {
      self.setMetaAttr('stale', false);
    }
    return newValue;
  }, {
    src: cell
  });

  cachingCell.target = cell;
  cachingCell.ensureMetaCell();
  cachingCell.propagateMeta = null;

  cachingCell.delegateInvalidationMethods(cell);

  return cachingCell;
};

Cell.prototype.delegateInvalidationMethods = function (target) {
  var self = this;
  _.each(("recalculate recalculateAt recalculateAfterDelay invalidate").split(' '), function (methodName) {
    self[methodName] = $m(target, methodName);
  });
};

Cell.mkCaching = function (formula, sources) {
  var cell = new Cell(formula, sources);
  return Cell.cacheResponse(cell);
};

future.get = function (ajaxOptions, valueTransformer, nowValue, futureWrapper) {
  // var aborted = false;
  var options = {
    valueTransformer: valueTransformer,
    cancel: function () {
      // aborted = true;
      operation.cancel();
    },
    nowValue: nowValue
  };
  var operation;
  if (ajaxOptions.url === undefined) {
    throw new Error("url is undefined");
  }

  function initiateXHR(dataCallback) {
    var opts = {dataType: 'json',
                prepareReGet: function (opts) {
                  if (opts.errorMarker) {
                    // if we have error marker pass it to data
                    // callback now to mark error
                    if (!dataCallback.continuing(opts.errorMarker)) {
                      // if we were cancelled, cancel IOCenter
                      // operation
                      operation.cancel();
                    }
                  }
                },
                success: dataCallback};
    if (ajaxOptions.onError) {
      opts.error = function () {
        ajaxOptions.onError.apply(this, [dataCallback].concat(_.toArray(arguments)));
      };
    }
    operation = IOCenter.performGet(_.extend(opts, ajaxOptions));
  }
  return (futureWrapper || future)(initiateXHR, options);
};

future.pollingGET = function (ajaxOptions, valueTransformer, nowValue, futureWrapper) {
  var initiator = futureWrapper || future;
  var interval = 2000;
  if (ajaxOptions.interval) {
    interval = ajaxOptions.interval;
    delete ajaxOptions.interval;
  }
  return future.get(ajaxOptions, valueTransformer, nowValue, function (body, options) {
    return initiator(function (dataCallback) {
      var context = this;
      function dataCallbackWrapper(data) {
        if (!dataCallback.continuing(data)) {
          return;
        }
        setTimeout(function () {
          if (dataCallback.continuing(data)) {
            body.call(context, dataCallbackWrapper);
          }<commit_msg>implemented future.withEarlyTransformer<commit_after>Cell.prototype.propagateMeta = function () {
  var metaCell = this.ensureMetaCell();
  var staleMetaCell;
  var sourceCells = this.getSourceCells();

  if (metaCell.cancelRefresh) {
    metaCell.cancelRefresh();
  }

  for (var i = sourceCells.length - 1; i >= 0; i--) {
    var cell = sourceCells[i].metaCell;
    if (!cell || !cell.value) {
      continue;
    }
    var metaValue = cell.value;
    if (metaValue.stale) {
      staleMetaCell = cell;
      break;
    }
  }

  metaCell.setValueAttr(!!staleMetaCell, 'stale');

  var refreshSlave = new Slave($m(this, 'propagateMeta'));

  if (staleMetaCell) {
    staleMetaCell.changedSlot.subscribeWithSlave(refreshSlave);
  } else {
    for (var j = sourceCells.length - 1; j >= 0; j--) {
      var cell = sourceCells[j].metaCell;
      if (!cell) {
        continue;
      }
      cell.changedSlot.subscribeWithSlave(refreshSlave);
    }
  }

  metaCell.cancelRefresh = function () {
    refreshSlave.die();
    for (var i = sourceCells.length - 1; i >= 0; i--) {
      var cell = sourceCells[i].metaCell;
      if (!cell) {
        continue;
      }
      cell.changedSlot.cleanup();
    }
  };
};

Cell.STANDARD_ERROR_MARK = {"this is error marker":true};

Cell.cacheResponse = function (cell) {
  var cachingCell = new Cell(function () {
    var newValue = cell.value;
    var self = this.self;
    var oldValue = self.value;
    if (newValue === undefined) {
      if (oldValue === undefined) {
        return oldValue;
      }
      newValue = oldValue;
      self.setMetaAttr('loading', true);
      return newValue;
    }
    self.setMetaAttr('loading', false);
    if (newValue === Cell.STANDARD_ERROR_MARK) {
      newValue = oldValue;
      self.setMetaAttr('stale', true);
    } else {
      self.setMetaAttr('stale', false);
    }
    return newValue;
  }, {
    src: cell
  });

  cachingCell.target = cell;
  cachingCell.ensureMetaCell();
  cachingCell.propagateMeta = null;

  cachingCell.delegateInvalidationMethods(cell);

  return cachingCell;
};

Cell.prototype.delegateInvalidationMethods = function (target) {
  var self = this;
  _.each(("recalculate recalculateAt recalculateAfterDelay invalidate").split(' '), function (methodName) {
    self[methodName] = $m(target, methodName);
  });
};

Cell.mkCaching = function (formula, sources) {
  var cell = new Cell(formula, sources);
  return Cell.cacheResponse(cell);
};

future.get = function (ajaxOptions, valueTransformer, nowValue, futureWrapper) {
  // var aborted = false;
  var options = {
    valueTransformer: valueTransformer,
    cancel: function () {
      // aborted = true;
      operation.cancel();
    },
    nowValue: nowValue
  };
  var operation;
  if (ajaxOptions.url === undefined) {
    throw new Error("url is undefined");
  }

  function initiateXHR(dataCallback) {
    var opts = {dataType: 'json',
                prepareReGet: function (opts) {
                  if (opts.errorMarker) {
                    // if we have error marker pass it to data
                    // callback now to mark error
                    if (!dataCallback.continuing(opts.errorMarker)) {
                      // if we were cancelled, cancel IOCenter
                      // operation
                      operation.cancel();
                    }
                  }
                },
                success: dataCallback};
    if (ajaxOptions.onError) {
      opts.error = function () {
        ajaxOptions.onError.apply(this, [dataCallback].concat(_.toArray(arguments)));
      };
    }
    operation = IOCenter.performGet(_.extend(opts, ajaxOptions));
  }
  return (futureWrapper || future)(initiateXHR, options);
};

future.withEarlyTransformer = function (earlyTransformer) {
  return {
    // we return a function
    get: function (ajaxOptions, valueTransformer, newValue, futureWrapper) {
      // that will delegate to future.get, but...
      return future.get(ajaxOptions, valueTransformer, newValue, futureReplacement);
      // will pass our function instead of future
      function futureReplacement(initXHR) {
        // that function will delegate to real future
        return (future || futureWrapper)(function (dataCallback) {
          // and once future is started
          // will call original future start function replacing dataCallback
          dataCallbackReplacement.cell = dataCallback.cell;
          dataCallbackReplacement.async = dataCallback.async;
          dataCallbackReplacement.continuing = dataCallback.continuing;
          initXHR(dataCallbackReplacement);
          function dataCallbackReplacement(value, status, xhr) {
            // replaced dataCallback will invoke earlyTransformer
            earlyTransformer(value, status, xhr);
            // and will finally pass data to real dataCallback
            dataCallback(value);
          }
        });
      }
    }
  };
}

future.pollingGET = function (ajaxOptions, valueTransformer, nowValue, futureWrapper) {
  var initiator = futureWrapper || future;
  var interval = 2000;
  if (ajaxOptions.interval) {
    interval = ajaxOptions.interval;
    delete ajaxOptions.interval;
  }
  return future.get(ajaxOptions, valueTransformer, nowValue, function (body, options) {
    return initiator(function (dataCallback) {
      var context = this;
      function dataCallbackWrapper(data) {
        if (!dataCallback.continuing(data)) {
          return;
        }
        setTimeout(function () {
          if (dataCallback.continuing(data)) {
            body.call(context, dataCallbackWrapper);
          }
{'fraction_non_alphanumeric': 0.11684400722746437, 'fraction_numerical': 0.002007628990162618, 'mean_word_length': 2.5342319971621143, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, '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': '4253991', 'n_tokens_mistral': 2948, 'n_tokens_neox': 2843, 'n_words': 661}