diff options
| author | mo khan <mo@mokhan.ca> | 2017-01-14 12:25:27 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2017-01-14 12:25:27 -0700 |
| commit | 07938eff2c8705321298e94b99bba15622f7dd08 (patch) | |
| tree | d98ee239317a975d0c7139f1befaf76db8a96f59 | |
| parent | 40bfe8491fcbfb18f49846bdabe35e67112a01c8 (diff) | |
extract ApplicationCommand.
| -rw-r--r-- | app/services/commands/application-command.js | 9 | ||||
| -rw-r--r-- | app/services/commands/create-workout-command.js | 6 | ||||
| -rw-r--r-- | app/services/commands/login-command.js | 6 | ||||
| -rw-r--r-- | app/services/commands/logout-command.js | 6 |
4 files changed, 21 insertions, 6 deletions
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'); } } |
