<commit_before>import Orbit from 'orbit/core';
import MemoryStore from 'orbit/sources/memory_store';

var supportsLocalStorage = function() {
  try {
    return 'localStorage' in window && window['localStorage'] !== null;
  } catch(e) {
    return false;
  }
};

var LocalStore = function() {
  this.init.apply(this, arguments);
};

LocalStore.prototype = {
  constructor: LocalStore,

  init: function(schema, options) {
    Orbit.assert('Store\'s `schema` must be specified', schema);
    Orbit.assert('LocalStore requires Orbit.Promise be defined', Orbit.Promise);
    Orbit.assert('Your browser does not support local storage!', supportsLocalStorage());

    options = options || {};
    this.namespace = options['namespace'] || 'orbit'; // local storage key
    this._autosave = options['autosave'] !== undefined ? options['autosave'] : true;
    var autoload = options['autoload'] !== undefined ? options['autoload'] : true;

    this._store = new MemoryStore(schema);
    this._isDirty = false;

    // Evented interface
    Orbit.expose(this, this._store, 'on', 'off', 'emit', 'poll', 'listeners', 'resolve', 'settle');

    // Transformable interface
    Orbit.expose(this, this._store, 'transform', 'didTransform', 'transformQueue');

    // Requestable interface
    Orbit.expose(this, this._store, 'find', 'add', 'update', 'patch', 'remove');

    // Cache interface
    Orbit.expose(this, this._store, 'retrieve', 'length', 'isDeleted');

    this._store.on('didTransform', function() {
      this._saveData();
    }, this);

    if (autoload) this.load();
  },

  load: function() {
    var storage = window.localStorage.getItem(this.namespace);
    this._store.reset(storage ? JSON.parse(storage) : {});
  },

  enableAutosave: function() {
    if (!this._autosave) {
      this._autosave = true;
      if (this._isDirty) this._saveData();
    }
  },

  disableAutosave: function() {
    if (this._autosave) {
      this._autosave = false;
    }
  },

  /////////////////////////////////////////////////////////////////////////////
  // Internals
  /////////////////////////////////////////////////////////////////////////////

  _saveData: function(forceSave) {
    if (!this._autosave && !forceSave) {
      this._isDirty = true;
      return;
    }
    window.localStorage.setItem(this.namespace, JSON.stringify(this._store.retrieve()));
    this._isDirty = false;
  }
};

export default LocalStore;<commit_msg>LocalStore extends rather than encapsulates MemoryStore<commit_after>import Orbit from 'orbit/core';
import MemoryStore from 'orbit/sources/memory_store';

var supportsLocalStorage = function() {
  try {
    return 'localStorage' in window && window['localStorage'] !== null;
  } catch(e) {
    return false;
  }
};

var LocalStore = function() {
  this.init.apply(this, arguments);
};

Orbit.extend(LocalStore.prototype, MemoryStore.prototype, {
  constructor: LocalStore,

  init: function(schema, options) {
    Orbit.assert('Your browser does not support local storage!', supportsLocalStorage());

    MemoryStore.prototype.init.apply(this, arguments);

    options = options || {};
    this.namespace = options['namespace'] || 'orbit'; // local storage key
    this._autosave = options['autosave'] !== undefined ? options['autosave'] : true;
    var autoload = options['autoload'] !== undefined ? options['autoload'] : true;

    this._isDirty = false;

    this.on('didTransform', function() {
      this._saveData();
    }, this);

    if (autoload) this.load();
  },

  load: function() {
    var storage = window.localStorage.getItem(this.namespace);
    this.reset(storage ? JSON.parse(storage) : {});
  },

  enableAutosave: function() {
    if (!this._autosave) {
      this._autosave = true;
      if (this._isDirty) this._saveData();
    }
  },

  disableAutosave: function() {
    if (this._autosave) {
      this._autosave = false;
    }
  },

  /////////////////////////////////////////////////////////////////////////////
  // Internals
  /////////////////////////////////////////////////////////////////////////////

  _saveData: function(forceSave) {
    if (!this._autosave && !forceSave) {
      this._isDirty = true;
      return;
    }
    window.localStorage.setItem(this.namespace, JSON.stringify(this.retrieve()));
    this._isDirty = false;
  }
});

export default LocalStore;
{'fraction_non_alphanumeric': 0.21324717285945072, 'fraction_numerical': 0.0, 'mean_word_length': 2.6267782426778243, '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': '2634608', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1247, 'n_words': 268}