import { takeUntil } from 'rxjs/operators' ; import { Component , OnInit , OnDestroy } from '@angular/core' ; import { WorkItemsStore } from './work-items.store' ; import { Subject } from 'rxjs' ; @ Component ( { selector : 'thy-store-basic' , templateUrl : './basic.component.html' , providers : [ WorkItemsStore ] } ) export class ThyStoreBasicExampleComponent implements OnInit , OnDestroy { private destroy$ = new Subject ( ) ; constructor ( public workItemsStore ) { } ngOnInit ( ) { this . fetchWorkItems ( ) . subscribe ( ( ) => { } , error => { } ) ; this . workItemsStore . select ( state => state . workItems ) . pipe ( takeUntil ( this . destroy$ ) ) . subscribe ( ( ) => { console . log ( 'work items changed' ) ; } ) ; } fetchWorkItems ( ) { return this . workItemsStore . fetchWorkItems ( ) ; } addWorkItem ( ) { this . workItemsStore . addWorkItem ( ) ; } deleteWorkItem ( id ) { this . workItemsStore . deleteWorkItem ( id ) ; } ngOnDestroy ( ) { this . destroy$ . next ( ) ; this . destroy$ . complete ( ) ; } }