import Ember from 'ember';
import { task } from 'ember-concurrency';

const {
  get,
  String: { capitalize }
} = Ember;

export default Ember.Service.extend({

  resource: null,

  send(model, action, ...options){
    const store = get(this, 'store');
    const callbackName = `on${capitalize(action)}${capitalize(get(this, 'resource'))}`;
    return get(this, `${action}Task`).perform(store, callbackName, model, ...options);
  },

  createTask: task(function * (store, callback){
    const model = yield store.createRecord( get(this, 'resource') );
    return { callback, model };
  }),

  saveTask: task(function * (store, callback, model){
    yield model.save();
    return { callback, model };
  }),

  rollbackTask: task(function * (store, callback, model){
    yield model.rollbackAttributes();
    return { callback, model };
  }),

  deleteTask: task(function * (store, callback, model){
    yield model.destroy();
    return { callback, model };
  })

});

@@ -703,24 +703,22 @@
  %7D),%0A%0A  
-rollback
+delete
 Task: ta
@@ -777,27 +777,148 @@
 del.
-rollbackAttributes(
+destroy();%0A    return %7B callback, model %7D;%0A  %7D),%0A%0A  unloadTask: task(function * (store, callback, model)%7B%0A    yield store.unloadRecord(model
 );%0A 
@@ -949,38 +949,40 @@
 del %7D;%0A  %7D),%0A%0A  
-delete
+rollback
 Task: task(funct
@@ -1021,39 +1021,50 @@
     yield model.
-destroy
+rollbackAttributes
 ();%0A    return %7B

Include unloadTask