Fixed too early single-model updates in the BaseRepository
This commit is contained in:
parent
b86054c4b9
commit
f392b479ba
@ -109,6 +109,16 @@ export class UpdateSlot {
|
|||||||
return this.deletedModels;
|
return this.deletedModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns all changed and deleted model ids in one array. If an id was
|
||||||
|
* changed and deleted, it will be there twice! But this should not be the case.
|
||||||
|
*/
|
||||||
|
public getAllModelsIdsForCollection(collection: string): number[] {
|
||||||
|
return this.getDeletedModelIdsForCollection(collection).concat(
|
||||||
|
this.getChangedModelIdsForCollection(collection)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares this object to another update slot.
|
* Compares this object to another update slot.
|
||||||
*/
|
*/
|
||||||
@ -232,7 +242,7 @@ export class DataStoreUpdateManagerService {
|
|||||||
|
|
||||||
// Phase 2: updating all repositories
|
// Phase 2: updating all repositories
|
||||||
repositories.forEach(repo => {
|
repositories.forEach(repo => {
|
||||||
repo.commitUpdate();
|
repo.commitUpdate(slot.getAllModelsIdsForCollection(repo.collectionString));
|
||||||
});
|
});
|
||||||
|
|
||||||
slot.DS.triggerModifiedObservable();
|
slot.DS.triggerModifiedObservable();
|
||||||
|
@ -172,7 +172,6 @@ export abstract class BaseRepository<V extends BaseViewModel & T, M extends Base
|
|||||||
public deleteModels(ids: number[]): void {
|
public deleteModels(ids: number[]): void {
|
||||||
ids.forEach(id => {
|
ids.forEach(id => {
|
||||||
delete this.viewModelStore[id];
|
delete this.viewModelStore[id];
|
||||||
this.updateViewModelObservable(id);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +184,6 @@ export abstract class BaseRepository<V extends BaseViewModel & T, M extends Base
|
|||||||
public changedModels(ids: number[]): void {
|
public changedModels(ids: number[]): void {
|
||||||
ids.forEach(id => {
|
ids.forEach(id => {
|
||||||
this.viewModelStore[id] = this.createViewModelWithTitles(this.DS.get(this.collectionString, id));
|
this.viewModelStore[id] = this.createViewModelWithTitles(this.DS.get(this.collectionString, id));
|
||||||
this.updateViewModelObservable(id);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +280,7 @@ export abstract class BaseRepository<V extends BaseViewModel & T, M extends Base
|
|||||||
*/
|
*/
|
||||||
public setSortFunction(fn: (a: V, b: V) => number): void {
|
public setSortFunction(fn: (a: V, b: V) => number): void {
|
||||||
this.viewModelSortFn = fn;
|
this.viewModelSortFn = fn;
|
||||||
this.commitUpdate();
|
this.commitUpdate(Object.keys(this.viewModelSubjects).map(x => +x));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -356,7 +354,10 @@ export abstract class BaseRepository<V extends BaseViewModel & T, M extends Base
|
|||||||
/**
|
/**
|
||||||
* update the observable of the list. Also updates the sorting of the view model list.
|
* update the observable of the list. Also updates the sorting of the view model list.
|
||||||
*/
|
*/
|
||||||
public commitUpdate(): void {
|
public commitUpdate(modelIds: number[]): void {
|
||||||
this.unsafeViewModelListSubject.next(this.getViewModelList());
|
this.unsafeViewModelListSubject.next(this.getViewModelList());
|
||||||
|
modelIds.forEach(id => {
|
||||||
|
this.updateViewModelObservable(id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import { DataStoreService } from '../../core-services/data-store.service';
|
|||||||
|
|
||||||
const WorkflowRelations: RelationDefinition[] = [
|
const WorkflowRelations: RelationDefinition[] = [
|
||||||
{
|
{
|
||||||
type: 'M2M',
|
type: 'O2M',
|
||||||
ownIdKey: 'states_id',
|
ownIdKey: 'states_id',
|
||||||
ownKey: 'states',
|
ownKey: 'states',
|
||||||
foreignViewModel: ViewState
|
foreignViewModel: ViewState
|
||||||
|
Loading…
Reference in New Issue
Block a user