Created
January 25, 2017 16:17
-
-
Save hanssens/9717d8b84371c55caa390997b772f53f to your computer and use it in GitHub Desktop.
Example pub/sub with Aurelia's EventAggregator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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