Skip to content

Instantly share code, notes, and snippets.

@freshcutdevelopment
Created September 16, 2017 10:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save freshcutdevelopment/2476acf6b0773d97c7d440fd0f23d8c8 to your computer and use it in GitHub Desktop.
Aurelia code quality - part 5
import {inject} from 'aurelia-framework';
import {EventAggregator} from 'aurelia-event-aggregator'; //import the EventAggregator class
import {GreeterService} from './services/greeter-service.js';
@inject(GreeterService, EventAggregator)
export class Greeter{
constructor(greeterService, eventAggregator){
this.greeterService = greeterService;
this.eventAggregator = eventAggregator;
}
attached(){ //called when the greeter component is attached to the DOM
this.greetings = this.greeterService.loadGreetings();
}
addGreeting(){
this.greetings.add(this.greeting); //add a new greeting to the list
this.eventAggregator.publish(`greeting-added`, this.greeting);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment