<commit_before>angular.module(PKG.name + '.services')

  .factory('mySettings', function (MyConfigStore) {
    return new MyConfigStore('consolesettings');
  })

  .factory('MyConfigStore', function MyConfigStoreFactory($q, MyDataSource, myHelpers) {

    var data = new MyDataSource();

    function MyConfigStore (type) {
      this.endpoint = '/configuration/'+type;

      // our cache of the server-side data
      this.data = {};

      // flag so we dont fire off multiple similar queries
      this.pending = null;
    }

    /**
     * set a preference
     * @param {string} key, can have a path like "foo.bar.baz"
     * @param {mixed} value
     * @return {promise} resolved with the response from server
     */
    MyConfigStore.prototype.set = function (key, value) {
      var deferred = $q.defer();

      myHelpers.deepSet(this.data, key, value);

      data.request(
        {
          method: 'PUT',
          _cdapPath: this.endpoint,
          body: this.data
        },
        deferred.resolve
      );

      return deferred.promise;
    };


    /**
     * retrieve a preference
     * @param {string} key
     * @param {boolean} force true to bypass cache
     * @return {promise} resolved with the value
     */
    MyConfigStore.prototype.get = function (key, force) {
      if (!force && this.data[key]) {
        return $q.when(this.data[key]);
      }

      var self = this;

      if (this.pending) {
        var deferred = $q.defer();
        this.pending.promise.then(function () {
          deferred.resolve(self.data[key]);
        });
        return deferred.promise;
      }

      this.pending = $q.defer();

      data.request(
        {
          method: 'GET',
          _cdapPath: this.endpoint
        },
        function (res) {
          self.data = res.property;
          self.pending.resolve(self.data[key]);
        }
      );

      var promise = this.pending.promise;

      promise.finally(function () {
        self.pending = null;
      });

      return promise;
    };

    return MyConfigStore;<commit_msg>use deepGet in mySettings<commit_after>angular.module(PKG.name + '.services')

  .factory('mySettings', function (MyConfigStore) {
    return new MyConfigStore('consolesettings');
  })

  .factory('MyConfigStore', function MyConfigStoreFactory($q, MyDataSource, myHelpers) {

    var data = new MyDataSource();

    function MyConfigStore (type) {
      this.endpoint = '/configuration/'+type;

      // our cache of the server-side data
      this.data = {};

      // flag so we dont fire off multiple similar queries
      this.pending = null;
    }

    /**
     * set a preference
     * @param {string} key, can have a path like "foo.bar.baz"
     * @param {mixed} value
     * @return {promise} resolved with the response from server
     */
    MyConfigStore.prototype.set = function (key, value) {
      var deferred = $q.defer();

      myHelpers.deepSet(this.data, key, value);

      data.request(
        {
          method: 'PUT',
          _cdapPath: this.endpoint,
          body: this.data
        },
        deferred.resolve
      );

      return deferred.promise;
    };


    /**
     * retrieve a preference
     * @param {string} key
     * @param {boolean} force true to bypass cache
     * @return {promise} resolved with the value
     */
    MyConfigStore.prototype.get = function (key, force) {

      var val = myHelpers.deepGet(this.data, key);

      if (!force && val) {
        return $q.when(val);
      }

      var self = this;

      if (this.pending) {
        var deferred = $q.defer();
        this.pending.promise.then(function () {
          deferred.resolve(
            myHelpers.deepGet(self.data, key)
          );
        });
        return deferred.promise;
      }

      this.pending = $q.defer();

      data.request(
        {
          method: 'GET',
          _cdapPath: this.endpoint
        },
        function (res) {
          self.data = res.property;
          self.pending.resolve(
            myHelpers.deepGet(self.data, key)
          );
        }
      );

      var promise = this.pending.promise;

      promise.finally(function () {
        self.pending = null;
      });

      return promise;
    };

    return MyConfigStore;
{'fraction_non_alphanumeric': 0.12315270935960591, 'fraction_numerical': 0.0, 'mean_word_length': 1.9265614275909402, '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': '6925297', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1224, 'n_words': 300}