ngrx-model
Version:
Model classes for integrating ngrx store with a REST API
41 lines (31 loc) • 1.31 kB
text/typescript
import { Observable } from 'rxjs';
import { RequestService } from '../request/request.service';
import { BaseModel, IBaseModelConfig } from './baseModel';
import { SingletonModel } from './singletonModel';
export interface ICollectionModelConfig<T> extends IBaseModelConfig<T[]> {
}
export class CollectionModel<T> extends BaseModel<T[]> {
constructor(config: ICollectionModelConfig<T>, request: RequestService) {
super(config, request);
}
add(newModel: T): Observable<T> {
// make a request, then add the item and push the updated list to the stream and return the request observable
return null;
}
update(newModel: T, oldModel: T): Observable<T> {
// make a request, then update the list, push to the stream, and return the request observable
return null;
}
remove(model: T): Observable<void> {
// make a request, then remove the item, push to the stream, and return the request observable
return null;
}
select(id: number): SingletonModel<T> {
// get a singleton model by id. Should 'map' the data stream observable
// return new SingletonModel<T>();
return null;
// to convert to a singleton we essentially need:
// to map the stream to get only the item with that id
// convert `Update` calls to updates on the list
}
}