import { Injectable } from '@angular/core' ; import { Action , EntityStore , EntityState } from 'ngx-tethys' ; import { produce } from 'ngx-tethys/util' ; import { of } from 'rxjs' ; import { map , tap } from 'rxjs/operators' ; import { workItemResponseData , addWorkItemResponseData } from '../work-items.mock' ; export interface WorkItemInfo { } export interface WorkItemsState extends EntityState < WorkItemInfo > { } @ Injectable ( ) export class WorkItemsStore extends EntityStore < WorkItemsState , WorkItemInfo > { constructor ( ) { super ( ) ; } @ Action ( ) fetchWorkItems ( ) { return of ( workItemResponseData ) . pipe ( map ( data => { this . initialize ( data . value , { pageIndex : data . page_index , pageSize : data . page_size , pageCount : data . page_count , count : data . count } ) ; } ) ) ; } @ Action ( ) addWorkItem ( ) { return of ( addWorkItemResponseData ) . pipe ( map ( data => { this . add ( data . value , { prepend : true } ) ; return true ; } ) ) ; } @ Action ( ) updateWorkItem ( id , partial ) { return of ( true ) . pipe ( map ( data => { this . update ( id , partial ) ; return true ; } ) ) ; } @ Action ( ) deleteWorkItem ( id ) { return of ( true ) . pipe ( map ( data => { this . remove ( id ) ; return data ; } ) ) ; } }