From 07938eff2c8705321298e94b99bba15622f7dd08 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 14 Jan 2017 12:25:27 -0700 Subject: extract ApplicationCommand. --- app/services/commands/application-command.js | 9 +++++++++ app/services/commands/create-workout-command.js | 6 ++++-- app/services/commands/login-command.js | 6 ++++-- app/services/commands/logout-command.js | 6 ++++-- 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 app/services/commands/application-command.js diff --git a/app/services/commands/application-command.js b/app/services/commands/application-command.js new file mode 100644 index 0000000..ceb38f0 --- /dev/null +++ b/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"); + } +} diff --git a/app/services/commands/create-workout-command.js b/app/services/commands/create-workout-command.js index 556a71f..ab4a3f9 100644 --- a/app/services/commands/create-workout-command.js +++ b/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, diff --git a/app/services/commands/login-command.js b/app/services/commands/login-command.js index 4b28c6d..9931f7a 100644 --- a/app/services/commands/login-command.js +++ b/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)); } diff --git a/app/services/commands/logout-command.js b/app/services/commands/logout-command.js index 28df698..f8ba006 100644 --- a/app/services/commands/logout-command.js +++ b/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'); } } -- cgit v1.2.3