
var SimpleStore = require('fh-wfm-simple-store'),
  config = require('./config.js');

/**
 * Creates and initializes a store to be used by the app modules.
 * @param {String} dataSetId  String used as an identifier for the store
 * @param {Object|null} seedData  Object to be saved in the store initially
 * @param {Object} mediator Object used for listening to a topic.
 */
function initStore(dataSetId, seedData, mediator) {
  var dataStore = new SimpleStore(dataSetId);

  /**
   * Check if existing data exists. If no existing data is found, initialize with the given seed data. Otherwise,
   * continue to listen to topic.
   *
   * TODO: Check for existing data may be removed in production as applications are likely to start with no
   * initial data. Instead, initialize store with: dataStore.init();
   */
  dataStore.list().then(function(storeData) {
    if (!storeData || storeData.length === 0) {
      //Check if seed data is given, otherwise initialize store with no initial data.
      if (seedData) {
        dataStore.init(seedData).then(function() {
          dataStore.listen(config.get('dataTopicPrefix'), mediator);
        });
      } else {
        dataStore.init().then(function() {
          dataStore.listen(config.get('dataTopicPrefix'), mediator);
        });
      }
    } else {
      dataStore.listen(config.get('dataTopicPrefix'), mediator);
    }
  });
}

module.exports = {
  init: initStore
};

@@ -1000,173 +1000,200 @@
     
-if (seedData) %7B%0A        dataStore.init(
+//array store needs to be initialized with an empty array if there is no 
 seed
-Data).then(function() %7B%0A          dataStore.listen(config.get('dataTopicPrefix'), mediator);%0A        %7D);%0A      %7D else %7B%0A  
+ data given.%0A      if (!seedData && process.env.WFM_USE_MEMORY_STORE === %22true%22) %7B%0A        seedData = %5B%5D;%0A      %7D%0A%0A
     
@@ -1209,16 +1209,24 @@
 re.init(
+seedData
 ).then(f
@@ -1233,26 +1233,24 @@
 unction() %7B%0A
-  
         data
@@ -1314,22 +1314,12 @@
     
-  
 %7D);%0A
-      %7D%0A
     

Initialize array store with an empty array