Skip to content

Instantly share code, notes, and snippets.

@hanssens
Created January 25, 2017 16:17
Show Gist options
  • Save hanssens/9717d8b84371c55caa390997b772f53f to your computer and use it in GitHub Desktop.
Save hanssens/9717d8b84371c55caa390997b772f53f to your computer and use it in GitHub Desktop.
Example pub/sub with Aurelia's EventAggregator
// the PUB:
import {EventAggregator} from 'aurelia-event-aggregator';
@inject(EventAggregator)
export class YourClass {
constructor(EventAggregator) {
this.ea = EventAggregator;
}
attached() {
this.ea.publish('filterApplied', {
// pass along an object here...
from: new Date(),
until: new Date()
});
}
}
// the SUB:
import {inject} from 'aurelia-framework';
import {EventAggregator} from 'aurelia-event-aggregator';
@inject(EventAggregator)
export class YourViewModel {
constructor(EventAggregator) {
this.ea = EventAggregator;
}
attached() {
this.ea.subscribe('filterApplied', (obj) => {
console.log('Hoorah!', obj);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment