What is this?
Practice library that manages the global cart state of a user.
Installation
npm i yujan-cart-manager
Then...
import { CartManager } from 'yujan-cart-manager';
const cartManager = new CartManager();
Definition
- CartItem object - object must have an id and quantity ex.
{
id: 1,
quantity: 0
}
- CallbackFunction - callback function with a parameter of CartItem list ex.
const callbackFunction = (latestCartValues) => {};
Properties
- cartItems - list of CartItem object
Methods
- pushItem(CartItem) - method to add an item to cart
- updateItem(CartItem) - method to update quantity of item in cart
- removeItem(CartItem) - method to remove item in cart
- subscribeCartUpdates(CallbackFunction) - method to subscribe for any updates to the cart state