check if unique is already in the array

This commit is contained in:
Mads Rasmussen
2024-08-05 15:05:52 +02:00
parent 6472d98088
commit f31f1e82fa

View File

@@ -22,7 +22,9 @@ export class UmbStateManager<StateType extends UmbState = UmbState> extends UmbC
*/
addState(state: StateType) {
if (!state.unique) throw new Error('State must have a unique property');
// TODO: check if unique is already in the array
if (this._states.getValue().find((x) => x.unique === state.unique)) {
throw new Error('State with unique already exists');
}
this._states.setValue([...this._states.getValue(), state]);
}