Last active
April 10, 2018 21:57
-
-
Save kmaraz/d03570a350038b16ecf392e07535e03b to your computer and use it in GitHub Desktop.
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
@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