We have Product
instances that we are adding to a shopping cart that is backed by a Firefly Semantics Slice Entity Store (EStore
).
As the Widget instances are added to the cart we wish to display an updated count
of the items.
Approach
The Firefly Semantics Entity Store has a count()
Observable<number>
reference that we can subscribe
to in order to receive the updated count
.
interface Product {
id: string;
name: string;
}
const P1: Product = {
id: '1',
name: 'Soap',
};
const P2: Product = {
id: '1',
name: 'Soap',
};
const cart: EStore<Product> = new EStore<Product>();
cart.count().subscribe((count) => console.log(count));
cart.post(P1);
cart.post(P2);