Skip to content

Instantly share code, notes, and snippets.

@kmaraz
Last active April 10, 2018 21:57
Show Gist options
  • Save kmaraz/d03570a350038b16ecf392e07535e03b to your computer and use it in GitHub Desktop.
Save kmaraz/d03570a350038b16ecf392e07535e03b to your computer and use it in GitHub Desktop.
@Component({
selector: 'events',
templateUrl: './events.component.html'
})
export class EventsComponent implements OnDestroy, OnInit {
events: Event[]; // Event list
private eventsSub: Subscription;
constructor(
// Multiple stores are replaced by one global store
private store: Store<fromEvents.State>
) {
// Subscriptions
this.eventsSub = this.store.select(fromEvents.selectevents)
.subscribe((events) => this.events = events);
}
ngOnInit() {
this.store.dispatch(new EventsActions.FetchAll());
}
ngOnDestroy() {
this.eventsSub.unsubscribe();
// Remove data from the events store
this.store.dispatch(new EventsActions.Reset());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment