Commit 8321c71
Changed files (3)
app
infrastructure
__tests__
reducers
__tests__
app/infrastructure/__tests__/event_aggregator_spec.js
@@ -0,0 +1,27 @@
+import EventAggregator from '../event-aggregator';
+
+describe("EventAggregator", () => {
+ let subject = null;
+
+ beforeEach(() => {
+ subject = new EventAggregator();
+ });
+
+ describe("publish", () => {
+ class TestSubscriber {
+ notify(event) {
+ this.called = true;
+ this.calledWith = event;
+ }
+ }
+
+ it ("publishes the event to all interested subscribers", () => {
+ let subscriber = new TestSubscriber();
+ subject.subscribe('LOGGED_IN', subscriber);
+ subject.publish({ event: 'LOGGED_IN', username: 'blah' })
+
+ expect(subscriber.called).toBeTruthy();
+ expect(subscriber.calledWith.username).toEqual('blah');
+ });
+ });
+});
app/infrastructure/event-aggregator.js
@@ -0,0 +1,14 @@
+
+export default class EventAggregator {
+ constructor() {
+ this.subscribers = [];
+ }
+
+ subscribe(event, subscriber) {
+ this.subscribers.push(subscriber);
+ }
+
+ publish(event) {
+ this.subscribers.forEach(x => x.notify(event));
+ }
+}
app/reducers/__tests__/stronglifters_spec.js
@@ -1,6 +1,5 @@
import stronglifters from '../stronglifters';
-
describe('stronglifters', () => {
let subject = stronglifters;