implement and use appendToFrozenArray
This commit is contained in:
@@ -2,6 +2,7 @@ import { UmbWorkspaceContentContext } from '../../../shared/components/workspace
|
||||
import type { UmbDataTypeStore, UmbDataTypeStoreItemType } from 'src/backoffice/settings/data-types/data-type.store';
|
||||
import type { DataTypeDetails } from '@umbraco-cms/models';
|
||||
import { UmbControllerHostInterface } from 'src/core/controller/controller-host.mixin';
|
||||
import { appendToFrozenArray } from 'src/core/observable-api/unique-behavior-subject';
|
||||
|
||||
const DefaultDataTypeData = {
|
||||
key: '',
|
||||
@@ -26,18 +27,11 @@ export class UmbWorkspaceDataTypeContext extends UmbWorkspaceContentContext<
|
||||
public setPropertyValue(alias: string, value: unknown) {
|
||||
|
||||
// TODO: make sure to check that we have a details model? otherwise fail? 8This can be relevant if we use the same context for tree actions?
|
||||
const data = this._data.getValue();
|
||||
|
||||
const entry = {alias: alias, value: value};
|
||||
|
||||
// TODO: Can we move this into a method of its own?
|
||||
const newDataSet = [...(data as DataTypeDetails).data];
|
||||
const indexToReplace = newDataSet.findIndex(x => x.alias === alias);
|
||||
if(indexToReplace !== -1) {
|
||||
newDataSet[indexToReplace] = entry;
|
||||
} else {
|
||||
newDataSet.push(entry);
|
||||
}
|
||||
const newDataSet = appendToFrozenArray((this._data.getValue() as DataTypeDetails).data, entry, x => x.alias === alias);
|
||||
|
||||
this.update({data: newDataSet});
|
||||
}
|
||||
|
||||
@@ -27,6 +27,35 @@ export function naiveObjectComparison(objOne: any, objTwo: any): boolean {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @method CreateObservablePart
|
||||
* @param {Observable<T>} source - RxJS Subject to use for this Observable.
|
||||
* @param {(mappable: T) => R} mappingFunction - Method to return the part for this Observable to return.
|
||||
* @param {(previousResult: R, currentResult: R) => boolean} [memoizationFunction] - Method to Compare if the data has changed. Should return true when data is different.
|
||||
* @description - Creates a RxJS Observable from RxJS Subject.
|
||||
* @example <caption>Example create a Observable for part of the data Subject.</caption>
|
||||
* public readonly myPart = CreateObservablePart(this._data, (data) => data.myPart);
|
||||
*/
|
||||
export function appendToFrozenArray<T>(data: T[], entry: T, uniqueMethod?: (entry: T) => boolean): T[] {
|
||||
const unFrozenDataSet = [...data];
|
||||
if(uniqueMethod) {
|
||||
const indexToReplace = unFrozenDataSet.findIndex(uniqueMethod);
|
||||
if(indexToReplace !== -1) {
|
||||
unFrozenDataSet[indexToReplace] = entry;
|
||||
} else {
|
||||
unFrozenDataSet.push(entry);
|
||||
}
|
||||
} else {
|
||||
unFrozenDataSet.push(entry);
|
||||
}
|
||||
return unFrozenDataSet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
type MappingFunction<T, R> = (mappable: T) => R;
|
||||
type MemoizationFunction<R> = (previousResult: R, currentResult: R) => boolean;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user