changes
This commit is contained in:
parent
9ec3000b85
commit
a911f739d8
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@poweredsoft/data",
|
||||
"version": "0.0.20",
|
||||
"version": "0.0.22",
|
||||
"peerDependencies": {
|
||||
"rxjs": "^6.5.3"
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import { IDataSourceOptions, IResolveCommandModelEvent } from '../public-api';
|
||||
|
||||
export class DataSource<TModel> implements IDataSource<TModel>
|
||||
{
|
||||
|
||||
data: IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel> = null;
|
||||
|
||||
protected _dataSubject: BehaviorSubject<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>> = new BehaviorSubject(null);
|
||||
@ -59,16 +58,29 @@ export class DataSource<TModel> implements IDataSource<TModel>
|
||||
this._data$ = this._dataSubject.asObservable();
|
||||
}
|
||||
|
||||
resolveIdField<TKeyType extends any>(model: TModel): TKeyType {
|
||||
|
||||
if (this.options.idField)
|
||||
return model[this.options.idField];
|
||||
|
||||
if (this.options.resolveIdField)
|
||||
return this.options.resolveIdField(model);
|
||||
|
||||
throw new Error("Must specify an id field or supply a method to resolve the id field.");
|
||||
}
|
||||
|
||||
|
||||
resolveCommandModelByName<T extends any>(event: IResolveCommandModelEvent<TModel>) : Observable<T> {
|
||||
|
||||
if (!this.options.transport.commands.hasOwnProperty(name))
|
||||
return Observable.throw(`command with name ${name} not found`);
|
||||
if (!this.options.transport.commands.hasOwnProperty(event.command))
|
||||
return Observable.throw(`command with name ${event.command} not found`);
|
||||
|
||||
const commandOptions = this.options.transport.commands[name];
|
||||
const commandOptions = this.options.transport.commands[event.command];
|
||||
if (commandOptions.resolveCommandModel)
|
||||
return commandOptions.resolveCommandModel(event);
|
||||
|
||||
return of<T>(event.model as any as T);
|
||||
const noResolveMethod: any = event.model || {};
|
||||
return of<T>(noResolveMethod as T);
|
||||
}
|
||||
|
||||
executeCommandByName<TCommand, TResult>(name: string, command: TCommand) : Observable<TResult> {
|
||||
|
@ -8,6 +8,7 @@ export interface IDataSource<TModel>
|
||||
executeCommandByName<TCommand, TResult>(name: string, command: TCommand) : Observable<TResult>;
|
||||
query<TQuery extends IQueryCriteria>(query: TQuery);
|
||||
refresh();
|
||||
resolveIdField<TKeyType extends any>(model: TModel) : TKeyType;
|
||||
|
||||
data$: Observable<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>;
|
||||
loading$: Observable<boolean>;
|
||||
|
@ -5,6 +5,8 @@ import { IQueryCriteria } from "./models";
|
||||
|
||||
export interface IDataSourceOptions<TModel> {
|
||||
transport: IDataSourceTransportOptions<TModel>;
|
||||
idField?: string;
|
||||
resolveIdField?: (model: TModel) => any;
|
||||
defaultCriteria: IQueryCriteria;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user