Commit 85282d4
Changed files (9)
app
screens
services
commands
queries
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()) {
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();
}
app/commands/__tests__/login-command_spec.js → app/services/commands/__tests__/login-command_spec.js
File renamed without changes
app/commands/index.js → app/services/commands/index.js
File renamed without changes
app/commands/login-command.js → 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
});
}
app/commands/logout-command.js → app/services/commands/logout-command.js
File renamed without changes
app/queries/fetch-workouts.js → 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 || []
});
}
app/queries/index.js → app/services/queries/index.js
File renamed without changes
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';