Seeking assistance with retrieving the last 3 values emitted. Despite using the provided code to populate uiOrder and invoking cancelOrderItem() multiple times, I am unable to access the last 3 revisions of the order via getHistory(). Instead, I receive the current value three times consecutively. Even attempting replaySubject(3) yields the same outcome.
export class OrdersService {
public readonly orders: Observable<Order[]>;
public readonly uiOrder: Observable<Order>;
private _orders: BehaviorSubject<Order[]>;
private _uiOrder: BehaviorSubject<Order>;
private dataStore: {
uiOrder: Order,
orders: Order[]
};
constructor() {
this.dataStore = {
uiOrder: null,
orders: []
};
this._orders = <BehaviorSubject<Order[]>>new BehaviorSubject([]);
this._uiOrder = <BehaviorSubject<Order>>new BehaviorSubject({});
this.orders = this._orders.asObservable();
this.uiOrder = this._uiOrder.asObservable();
}
getOrder(orderId: number | string) {
for (let i = 0; i < this.dataStore.orders.length; i++) {
if (this.dataStore.orders[i].id == orderId) {
this.dataStore.orders[i].lastAccess = moment().format().slice(0, 19) + 'Z';
this.dataStore.uiOrder = this.dataStore.orders[i];
this.updateUiOrder();
}
}
}
cancelOrderItem(action) {
this.dataStore.uiOrder.sections[action.sectionIndex].orderDetails.splice(action.orderDetailsIndex, 1);
this.updateUiOrder()
}
getHistory() {
this.uiOrder.take(3).subscribe((res) => {
console.log('uiOrder', res);
}).unsubscribe()
}
updateUiOrder() {
console.log('updating ui order');
this._uiOrder.next(this.dataStore.uiOrder);
}
}
What could be causing this issue?