summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2016-12-22 10:00:14 -0700
committermo khan <mo@mokhan.ca>2016-12-22 10:00:14 -0700
commit85282d4bab1b824173ff043013db85a7d8ec5df2 (patch)
tree3f277ffa5582ff49718be75d349b71a591037f8e
parentb6d9bef603bc789d085226bf66e4e943fd55e00e (diff)
convert string events to constants.
-rw-r--r--app/boot/wire-up-components-into.js4
-rw-r--r--app/screens/dashboard-screen.js9
-rw-r--r--app/services/commands/__tests__/login-command_spec.js (renamed from app/commands/__tests__/login-command_spec.js)0
-rw-r--r--app/services/commands/index.js (renamed from app/commands/index.js)0
-rw-r--r--app/services/commands/login-command.js (renamed from app/commands/login-command.js)9
-rw-r--r--app/services/commands/logout-command.js (renamed from app/commands/logout-command.js)0
-rw-r--r--app/services/events.js5
-rw-r--r--app/services/queries/fetch-workouts.js (renamed from app/queries/fetch-workouts.js)7
-rw-r--r--app/services/queries/index.js (renamed from app/queries/index.js)0
9 files changed, 21 insertions, 13 deletions
diff --git a/app/boot/wire-up-components-into.js b/app/boot/wire-up-components-into.js
index 995851a..bb192ea 100644
--- a/app/boot/wire-up-components-into.js
+++ b/app/boot/wire-up-components-into.js
@@ -1,8 +1,8 @@
import EventAggregator from '../infrastructure/event-aggregator';
import Registry from '../infrastructure/registry';
import Router from '../infrastructure/router'
-import * as commands from '../commands';
-import * as queries from '../queries';
+import * as commands from '../services/commands';
+import * as queries from '../services/queries';
export default class WireUpComponentsInto {
constructor(registry = new Registry()) {
diff --git a/app/screens/dashboard-screen.js b/app/screens/dashboard-screen.js
index efeda01..208fec0 100644
--- a/app/screens/dashboard-screen.js
+++ b/app/screens/dashboard-screen.js
@@ -4,12 +4,13 @@ import { Container, Header, Title, Content, Footer, FooterTab, Button, Icon, Spi
import ApplicationStorage from '../infrastructure/application-storage';
import ApplicationComponent from '../components/application-component';
import Workout from '../components/workout';
+import * as events from '../services/events';
export default class DashboardScreen extends ApplicationComponent {
constructor(props) {
super(props)
this.state = {
- eventsOfInterest: ['FETCHED_WORKOUTS'],
+ eventsOfInterest: [events.FETCHED_WORKOUTS],
workouts: [],
};
}
@@ -52,12 +53,12 @@ export default class DashboardScreen extends ApplicationComponent {
onLoadHistory() {
this.setState({isLoading: true})
- this.publish({event: 'FETCH_WORKOUTS'});
+ this.publish({event: events.FETCH_WORKOUTS});
}
notify(event) {
switch(event.event) {
- case "FETCHED_WORKOUTS":
+ case events.FETCHED_WORKOUTS:
this.setState({
isLoading: false,
workouts: event.workouts
@@ -70,7 +71,7 @@ export default class DashboardScreen extends ApplicationComponent {
}
onLogout() {
- this.publish({event: 'LOGOUT'})
+ this.publish({event: events.LOGOUT})
this.props.navigator.pop();
}
diff --git a/app/commands/__tests__/login-command_spec.js b/app/services/commands/__tests__/login-command_spec.js
index b4e9d77..b4e9d77 100644
--- a/app/commands/__tests__/login-command_spec.js
+++ b/app/services/commands/__tests__/login-command_spec.js
diff --git a/app/commands/index.js b/app/services/commands/index.js
index 9560f09..9560f09 100644
--- a/app/commands/index.js
+++ b/app/services/commands/index.js
diff --git a/app/commands/login-command.js b/app/services/commands/login-command.js
index fa7762e..061ca7d 100644
--- a/app/commands/login-command.js
+++ b/app/services/commands/login-command.js
@@ -1,5 +1,6 @@
-import Api from '../infrastructure/api';
-import ApplicationStorage from '../infrastructure/application-storage';
+import Api from '../../infrastructure/api';
+import ApplicationStorage from '../../infrastructure/application-storage';
+import * as events from '../events';
export default class LoginCommand {
constructor(eventAggregator, api = new Api('/sessions'), storage = new ApplicationStorage()) {
@@ -9,7 +10,7 @@ export default class LoginCommand {
}
subscribeTo(eventAggregator) {
- eventAggregator.subscribe('LOGIN', this);
+ eventAggregator.subscribe(events.LOGIN, this);
}
notify(event) {
@@ -20,7 +21,7 @@ export default class LoginCommand {
onResponse(json) {
this.storage.save('authentication_token', json.authentication_token);
this.eventAggregator.publish({
- event: 'LOGGED_IN',
+ event: events.LOGGED_IN,
...json
});
}
diff --git a/app/commands/logout-command.js b/app/services/commands/logout-command.js
index 0586997..0586997 100644
--- a/app/commands/logout-command.js
+++ b/app/services/commands/logout-command.js
diff --git a/app/services/events.js b/app/services/events.js
new file mode 100644
index 0000000..449ded1
--- /dev/null
+++ b/app/services/events.js
@@ -0,0 +1,5 @@
+export const LOGIN = 'LOGIN';
+export const LOGGED_IN = 'LOGGED_IN';
+export const LOGOUT = 'LOGOUT';
+export const FETCH_WORKOUTS = 'FETCH_WORKOUTS';
+export const FETCHED_WORKOUTS = 'FETCHED_WORKOUTS';
diff --git a/app/queries/fetch-workouts.js b/app/services/queries/fetch-workouts.js
index 819fc5f..4524b54 100644
--- a/app/queries/fetch-workouts.js
+++ b/app/services/queries/fetch-workouts.js
@@ -1,4 +1,5 @@
-import Api from '../infrastructure/api';
+import Api from '../../infrastructure/api';
+import * as events from '../events';
export default class FetchWorkouts {
constructor(eventAggregator, api = new Api('/workouts')) {
@@ -7,7 +8,7 @@ export default class FetchWorkouts {
}
subscribeTo(eventAggregator) {
- eventAggregator.subscribe('FETCH_WORKOUTS', this);
+ eventAggregator.subscribe(events.FETCH_WORKOUTS, this);
}
notify(event) {
@@ -16,7 +17,7 @@ export default class FetchWorkouts {
onResponse(json) {
this.eventAggregator.publish({
- event: 'FETCHED_WORKOUTS',
+ event: events.FETCHED_WORKOUTS,
workouts: json.workouts || []
});
}
diff --git a/app/queries/index.js b/app/services/queries/index.js
index 30087f6..30087f6 100644
--- a/app/queries/index.js
+++ b/app/services/queries/index.js