import storage from './libs/Storage';
import * as CONSTANTES from './constantes';

export const persistor = (recordAction = true, key) => {
  this.persistActionType = CONSTANTES.PERSIST_STORE;
  this.recordAction = recordAction;
  storage.initLocalStorage(key);
};

export const persistWithConditions = (currentState, action) => {
  if (!currentState) return;

  if (action.type === this.persistActionType) {
    this.setStorage(currentState);
  }
};

export const start = store => next => (action) => {
  const result = next(action);
  const currentState = store.getState();
  persistWithConditions(currentState, action);
  if (this.recordAction) {
    this.persistAction(action);
  }
  return result;
};

export const persistAction = (action) => {
  if (!action) return;
  const actionArray = this.getStorage('REDUX_RECOVER_ACTION') || [];

  if (actionArray.length === this.nbSavedActions) {
    actionArray.shift(action);
  } else {
    actionArray.push(action);
  }
  storage.setStorage('REDUX_RECOVER_ACTION', actionArray.reverse());
};

export const purge = () => new Promise((resolve, reject) => {
  storage.clearStorage();
  resolve();
});
@@ -834,28 +834,38 @@
 ) %7C%7C %5B%5D;%0A%0A  
-if (
+actionArray = 
 actionArray.
@@ -894,23 +894,18 @@
 dActions
-) %7B%0A  
  
+?
  actionA
@@ -926,36 +926,17 @@
 ion)
-;%0A  %7D else %7B%0A  
  
+:
  action
-Array
 .pus
@@ -946,20 +946,16 @@
 ction);%0A
-  %7D%0A
   storag
@@ -1123,8 +1123,9 @@
 e();%0A%7D);
+%0A

Update index.js