import CommandInvoker from '../commandInvoker';

class ActionsBase {

  service() { }

  getAllAction(data) { }

  insertAction(data) { }

  updateAction(data) { }

  destroyAction(id) { }

  loadData() {
    var self = this;
    return function(dispatch, getState) {
      var command = self.service().getAllCommand();
      return new CommandInvoker(dispatch).invoke(command, self.getAllAction);
    }
  }

  save(data) {
    var self = this;
    return function(dispatch, getState) {
      var { command, actionFunc } = getFunctionsFor(data);
      return new CommandInvoker(dispatch).invoke(command, actionFunc);

      function getFunctionsFor(data) {
        if (data.id) {
          return {
            command: self.service().updateCommand(data),
            actionFunc: self.updateAction
          };
        }
        return {
          command: self.service().insertCommand(data),
          actionFunc: self.insertAction
        };
      }
    }
  }

  destroy(id) {
    var self = this;
    return function(dispatch, getState) {
      var command = self.service().destroyCommand(id);
      return new CommandInvoker(dispatch).invoke(command, destroyCustomerSuccess(id));
    }

    function destroyCustomerSuccess(id) {
      return () => {
        return self.destroyAction(id);
      }
    }
  }
}

export default ActionsBase;
@@ -106,16 +106,41 @@
 a) %7B %7D%0A%0A
+  getByIdAction(id) %7B %7D%0A%0A
   insert
@@ -427,16 +427,240 @@
  %7D%0A  %7D%0A%0A
+  getById(id) %7B%0A    var self = this;%0A    return function(dispatch, getState) %7B%0A      var command = self.service().getByIdCommand(id);%0A      return new CommandInvoker(dispatch).invoke(command, self.getByIdAction);%0A    %7D%0A  %7D%0A%0A
   save(d

add getById() support