Create a gist now

Instantly share code, notes, and snippets.

Aurelia messaging app - Messages Component
import {EventAggregator} from 'aurelia-event-aggregator';
import {MessageService} from './services/message-service';
@inject(EventAggregator, MessageService)
export class Messages{
messages = [];
constructor(eventAggregator, messageService){
this.eventAggregator = eventAggregator;
this.messageService = messageService;
}
bind(){
this.messageService.list().then(messages => {
this.messages = messages;
});
}
attached(){
this.newMessageSubscription = this.eventAggregator.subscribe('new-message', message => {
this.messageService.save(message);
});
}
detached(){
this.newMessageSubscription.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment