<commit_before>var fw = require('knockout/build/output/knockout-latest');
var _ = require('footwork-lodash');

var privateDataSymbol = require('../../misc/util').getSymbol('footwork');
var dataTools = require('./data-tools');
var insertValueIntoObject = dataTools.insertValueIntoObject;
var getNestedReference = dataTools.getNestedReference;
var evalDirtyState = dataTools.evalDirtyState;

function isNode (thing) {
  var thingIsObject = _.isObject(thing);
  return (
    thingIsObject ? thing instanceof Node :
    thingIsObject && _.isNumber(thing.nodeType) === "number" && _.isString(thing.nodeName)
  );
}

/**
 * GET from server and set in model
 *
 * @param {object} options (optional) Options passed to sync()
 * @returns {object} Promise Promise for the HTTP Request
 */
function fetchModel (options) {
  var ajax = require('../../misc/ajax');
  var dataModel = this;
  var configParams = dataModel[privateDataSymbol].configParams;
  var requestInfo = {
    requestRunning: dataModel.isFetching,
    requestLull: configParams.requestLull,
    entity: dataModel,
    createRequest: function () {
      if (!dataModel.isNew()) {
        // retrieve data dataModel the from server using the id
        var xhr = dataModel.sync('read', dataModel, options);

        ajax.handleJsonResponse(xhr)
          .then(function handleResponseData (data) {
            var parsedData = configParams.parse ? configParams.parse.call(dataModel, data, 'read') : data;
            if (!_.isUndefined(parsedData[configParams.idAttribute])) {
              dataModel.set(parsedData);
            }
          });

        return xhr;
      } else {
        return Promise.reject(new Error("Must have ID provided to a dataModel in order to fetch its data"));
      }
    }
  };

  return ajax.makeOrGetRequest('fetch', requestInfo);
}

/**
 * PUT / POST / PATCH to server
 *
 * @param {string} (optional) attrs
 * @param {object} options (optional) Options passed to sync()
 * @returns {object} Promise Promise for the HTTP Request
 */
function save (attrs, options) {
  var ajax = require('../../misc/ajax');
  var dataModel = this;
  var configParams = dataModel[privateDataSymbol].configParams;
  var attrs = isNode(attrs) ? {} : attrs;

  options = _.extend({
    parse: true,
    wait: false,
    patch: false
  }, options);

  var method = dataModel.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
  if (method === 'patch' && !options.attrs) {
    options.attrs = attrs;
  }

  var requestInfo = {<commit_msg>removed dead code from dataModel save method<commit_after>var fw = require('knockout/build/output/knockout-latest');
var _ = require('footwork-lodash');

var privateDataSymbol = require('../../misc/util').getSymbol('footwork');
var dataTools = require('./data-tools');
var insertValueIntoObject = dataTools.insertValueIntoObject;
var getNestedReference = dataTools.getNestedReference;
var evalDirtyState = dataTools.evalDirtyState;

function isNode (thing) {
  var thingIsObject = _.isObject(thing);
  return (
    thingIsObject ? thing instanceof Node :
    thingIsObject && _.isNumber(thing.nodeType) === "number" && _.isString(thing.nodeName)
  );
}

/**
 * GET from server and set in model
 *
 * @param {object} options (optional) Options passed to sync()
 * @returns {object} Promise Promise for the HTTP Request
 */
function fetchModel (options) {
  var ajax = require('../../misc/ajax');
  var dataModel = this;
  var configParams = dataModel[privateDataSymbol].configParams;
  var requestInfo = {
    requestRunning: dataModel.isFetching,
    requestLull: configParams.requestLull,
    entity: dataModel,
    createRequest: function () {
      if (!dataModel.isNew()) {
        // retrieve data dataModel the from server using the id
        var xhr = dataModel.sync('read', dataModel, options);

        ajax.handleJsonResponse(xhr)
          .then(function handleResponseData (data) {
            var parsedData = configParams.parse ? configParams.parse.call(dataModel, data, 'read') : data;
            if (!_.isUndefined(parsedData[configParams.idAttribute])) {
              dataModel.set(parsedData);
            }
          });

        return xhr;
      } else {
        return Promise.reject(new Error("Must have ID provided to a dataModel in order to fetch its data"));
      }
    }
  };

  return ajax.makeOrGetRequest('fetch', requestInfo);
}

/**
 * PUT / POST / PATCH to server
 *
 * @param {string} (optional) attrs
 * @param {object} options (optional) Options passed to sync()
 * @returns {object} Promise Promise for the HTTP Request
 */
function save (attrs, options) {
  var ajax = require('../../misc/ajax');
  var dataModel = this;
  var configParams = dataModel[privateDataSymbol].configParams;
  var attrs = isNode(attrs) ? {} : attrs;

  options = _.extend({
    wait: false,
    patch: false
  }, options);

  var method = dataModel.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
  if (method === 'patch' && !options.attrs) {
    options.attrs = attrs;
  }

  var requestInfo = {
{'fraction_non_alphanumeric': 0.13100436681222707, 'fraction_numerical': 0.0, 'mean_word_length': 3.3931996512641676, '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': '7478889', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1458, 'n_words': 398}