Commit 07938ef

mo khan <mo@mokhan.ca>
2017-01-14 19:25:27
extract ApplicationCommand.
1 parent 40bfe84
app/services/commands/application-command.js
@@ -0,0 +1,9 @@
+export default class ApplicationCommand {
+  notify(event) {
+    this.run(event);
+  }
+
+  run(event) {
+    console.log("NOT IMPLEMENTED");
+  }
+}
app/services/commands/create-workout-command.js
@@ -1,7 +1,9 @@
 import * as events from '../events';
+import ApplicationCommand from './application-command';
 
-export default class CreateWorkoutCommand {
+export default class CreateWorkoutCommand extends ApplicationCommand {
   constructor(eventAggregator, api) {
+    super();
     this.eventAggregator = eventAggregator;
     this.api = api;
   }
@@ -10,7 +12,7 @@ export default class CreateWorkoutCommand {
     eventAggregator.subscribe(events.CREATE_WORKOUT, this);
   }
 
-  notify(event) {
+  run(event) {
     const body = {
       workout: {
         body_weight: event.body_weight,
app/services/commands/login-command.js
@@ -1,7 +1,9 @@
 import * as events from '../events';
+import ApplicationCommand from './application-command';
 
-export default class LoginCommand {
+export default class LoginCommand extends ApplicationCommand {
   constructor(eventAggregator, api, applicationStorage) {
+    super();
     this.eventAggregator = eventAggregator;
     this.api = api;
     this.applicationStorage = applicationStorage;
@@ -11,7 +13,7 @@ export default class LoginCommand {
     eventAggregator.subscribe(events.LOGIN, this);
   }
 
-  notify(event) {
+  run(event) {
     let body = { username: event.username, password: event.password };
     this.api.post('/sessions', body, this.onResponse.bind(this));
   }
app/services/commands/logout-command.js
@@ -1,7 +1,9 @@
 import * as events from '../events';
+import ApplicationCommand from './application-command';
 
-export default class LogoutCommand {
+export default class LogoutCommand extends ApplicationCommand {
   constructor(eventAggregator, applicationStorage) {
+    super();
     this.eventAggregator = eventAggregator;
     this.applicationStorage = applicationStorage;
   }
@@ -10,7 +12,7 @@ export default class LogoutCommand {
     eventAggregator.subscribe(events.LOGOUT, this);
   }
 
-  notify(event) {
+  run(event) {
     this.applicationStorage.delete('authentication_token');
   }
 }