Skip to content

Instantly share code, notes, and snippets.

@smcelhinney
Created April 16, 2015 23:47
Show Gist options
  • Save smcelhinney/97308bc89089295200a0 to your computer and use it in GitHub Desktop.
Save smcelhinney/97308bc89089295200a0 to your computer and use it in GitHub Desktop.
// Ordinarily, you would import this from another module...
class ObservableService {
constructor() {
this.callbacks = [];
}
subscribe(cb) {
this.callbacks.push(cb)
}
notify() {
this.callbacks.forEach(cb => {
cb();
})
}
}
class BookingService extends ObservableService {
constructor(AEMConfig) {
super();
// Use an injected property.
this.aemConfig = AEMConfig;
}
update() {
// Do something
}
static bookingFactory(AEMConfig) {
return new BookingService(AEMConfig);
}
}
BookingService.bookingFactory.$inject = ['AEMConfig'];
angular.module('booking').factory('Booking', BookingService.bookingFactory);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment