Commit 4960c96
Changed files (3)
app
app/components/application-component.js
@@ -2,12 +2,16 @@ import React, { Component } from 'react';
export default class ApplicationComponent extends Component {
componentDidMount() {
- console.log("MOUNTED");
- this.props.eventAggregator.subscribe('LOGGED_IN', this);
+ this.state.eventsOfInterest.forEach((event) => {
+ this.props.eventAggregator.subscribe(event, this);
+ });
}
componentWillUnmount() {
- console.log("UNMOUNTING");
this.props.eventAggregator.unsubscribe(this);
}
+
+ publish(event) {
+ this.props.eventAggregator.publish(event);
+ }
}
app/infrastructure/event-aggregator.js
@@ -4,10 +4,12 @@ export default class EventAggregator {
}
subscribe(event, subscriber) {
+ console.log(`subscribe to ${event}`);
this._subscriptionsFor(event).push(subscriber);
}
publish(event) {
+ console.log(`publish ${event}`);
this._subscriptionsFor(event.event).forEach(x => x.notify(event));
}
app/screens/login-screen.js
@@ -11,7 +11,10 @@ var Form = t.form.Form;
export default class LoginScreen extends ApplicationComponent {
constructor(props) {
super(props)
- this.state = { account: { username: 'mokha', password: '' } };
+ this.state = {
+ account: { username: 'mokha', password: '' },
+ eventsOfInterest: ['LOGGED_IN'],
+ };
}
render() {
@@ -39,7 +42,12 @@ export default class LoginScreen extends ApplicationComponent {
onLogin() {
let account = this.refs.form.getValue();
- this.props.login(account.username, account.password);
+ //this.props.login(account.username, account.password);
+ this.publish({
+ event: 'LOGIN',
+ username: account.username,
+ password: account.password
+ });
}
onChange(account) {