<commit_before>angular.module('snap')
  .factory('snapRemote', ['$q', function($q) {
    'use strict';

    // Provide direct access to the snapper object and a few convenience methods
    // for our directives.

    var deferred = $q.defer()
      , exports;
  
    exports = {
      get: function() {
        return deferred.promise;
      },

      register: function(snapper) {
        deferred.resolve(snapper);
      },

      toggle: function(side) {
        exports.get().then(function(snapper) {
          if(side === snapper.state().state) {
            exports.close(side);
          } else {
            exports.open(side);
          }
        });
      },

      open: function(side) {
        exports.get().then(function(snapper) {
          snapper.open(side);
        });
      },

      close: function() {
        exports.get().then(function(snapper) {
          snapper.close();
        });
      }
    };

    return exports;
  }]);<commit_msg>feature: Start building support for multiple snap instances<commit_after>angular.module('snap')
  .factory('snapRemote', ['$q', function($q) {
    'use strict';

    var snapperStore = {}
      , DEFAULT_SNAPPER_ID = '__DEFAULT_SNAPPER_ID__'
      , exports = {}
      , initStoreForId
      , resolveInStoreById;

    exports.get = function(id) {
      id = id || DEFAULT_SNAPPER_ID;
      if(!snapperStore.hasOwnProperty(id)) {
        initStoreForId(id);
      }
      return snapperStore[id].deferred.promise;
    };

    exports.register = function(snapper, id) {
      id = id || DEFAULT_SNAPPER_ID;
      if(!snapperStore.hasOwnProperty(id)) {
        initStoreForId(id);
      }
      if(snapperStore[id].isResolved) {
        initStoreForId(id);
      }
      resolveInStoreById(snapper, id);
    };

    exports.toggle = function(side, id) {
      id = id || DEFAULT_SNAPPER_ID;
      exports.get().then(function(snapper) {
        if(side === snapper.state().state) {
          exports.close(side);
        } else {
          exports.open(side);
        }
      });
    };

    exports.open = function(side, id) {
      id = id || DEFAULT_SNAPPER_ID;
      exports.get().then(function(snapper) {
        snapper.open(side);
      });
    };

    exports.close = function(id) {
      id = id || DEFAULT_SNAPPER_ID;
      exports.get().then(function(snapper) {
        snapper.close();
      });
    };

    initStoreForId = function(id) {
      snapperStore[id] = {
        deferred: $q.defer(),
        isResolved: false
      };
    };

    resolveInStoreById = function(snapper, id) {
      snapperStore[id].deferred.resolve(snapper);
      snapperStore[id].isResolved = true;
    };

    return exports;
  }]);
{'fraction_non_alphanumeric': 0.14397321428571427, 'fraction_numerical': 0.0, 'mean_word_length': 2.1086705202312137, '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': '4920822', 'n_tokens_mistral': 851, 'n_tokens_neox': 840, 'n_words': 134}