When it comes to adding items to an array BehaviorSubject, the common practice is to assign a copy of the entire array along with the new item using next()
.
However, I am looking for a way to push items into this array without having to assign a full copy, especially since I have other array operations to perform that are complex with BehaviorSubject.
Is there a method to achieve this without the need for copying the entire array, or is there an alternative to BehaviorSubject that could simplify this process? Additionally, are there any useful libraries that can assist with this?
For example:
export class ArrayService {
currentArray = new BehaviorSubject<[]>([]);
addItem(){
let newItem = 'newItem';
currentArray.next([...this.currentArray.getValue(), newItem]);
}
}