# Code coverage report for browser/Store/Memory.js

## Statements: 89.58% (43 / 48) Branches: 54.05% (20 / 37) Functions: 100% (9 / 9) Lines: 89.36% (42 / 47)

All files » browser/Store/ » Memory.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    971

    1

    1

    1
    1

    1
    1

    1

    1

    1

    1
    1

    1

    1

    1
    6

    1
    10
    1
    2

    9

    10

    1
    1
    1
    1

    1
    10
    10

    1
    2
    2
    2

    1
    2
    2
    2

    1
    1
    1

    1

    1

     (function (root, factory) {
      // Node.
      Iif(typeof module === 'object' && typeof module.exports === 'object') {
        exports = module.exports = factory();
      }

      // AMD.
      Iif(typeof define === 'function' && define.amd) {
        define([], factory);
      }

      // Browser Global.
      Eif(typeof root.navigator === "object") {
        Iif (typeof root.Terraformer === "undefined"){
          root.Terraformer = { };
        }
        Eif (typeof root.Terraformer.Store === "undefined"){
          root.Terraformer.Store = {};
        }
        root.Terraformer.Store.Memory = factory().Memory;
      }
    }(this, function() {
      var exports = { };

      var Terraformer;

      // Local Reference To Browser Global
      Eif(typeof this.navigator === "object") {
        Terraformer = this.Terraformer;
      }

      // Setup Node Dependencies
      Iif(typeof module === 'object' && typeof module.exports === 'object') {
        Terraformer = require('../terraformer.js');
      }

      // Setup AMD Dependencies
      Iif(arguments[0] && typeof define === 'function' && define.amd) {
        Terraformer = arguments[0];
      }

      // These methods get called in context of the geostore
      function Memory(){
        this.data = {};
      }

      // store the data at id returns true if stored successfully
      Memory.prototype.add = function(geojson, callback){
        if(geojson.type === "FeatureCollection"){
          for (var i = 0; i < geojson.features.length; i++) {
            this.data[geojson.features[i].id] = geojson.features[i];
          }
        } else {
          this.data[geojson.id] = geojson;
        }
        if ( callback ) callback( null, geojson);
      };

      // remove the data from the index and data with id returns true if removed successfully.
      Memory.prototype.remove = function(id, callback){
        delete this.data[id];
        Eif ( callback ) {
          callback( null, id );
        }
      };

      // return the data stored at id
      Memory.prototype.get = function(id, callback){
        Eif ( callback ) {
          callback( null, this.data[id] );
        }
      };

      Memory.prototype.update = function(geojson, callback){
        this.data[geojson.id] = geojson;
        Eif ( callback ) {
          callback( null );
        }
      };

      Memory.prototype.serialize = function(callback){
        var data = JSON.stringify(this.data);
        Eif ( callback ) {
          callback( null, data );
        }
      };

      Memory.prototype.deserialize = function(serializedStore){
        this.data = JSON.parse(serializedStore);
        return this;
      };

      exports.Memory = Memory;

      return exports;
    }));