Skip to content

Commit

Permalink
improved js docs for cart
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Oct 22, 2023
1 parent fd708da commit 82fb242
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
19 changes: 16 additions & 3 deletions _dev/js/theme/core/cart/cartController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ import useCustomQuantityInput from '../../components/useCustomQuantityInput';
const { on } = useEvent();

/**
* Cart controller
* @returns {object} return
* @returns {function} return.init initialize cart controller
* The Cart Controller manages interactions and events related to the shopping cart.
* @namespace cartController
* @returns {object} Returns an object with an `init` function to initialize the cart controller.
* @property {function} init - Initializes the cart controller by attaching event handlers to relevant DOM elements.
* @public
*/
const cartController = () => {
/**
* Attaches spinner events to custom cart quantity spinners.
* @private
* @function
*/
const attachSpinnerEvents = () => {
const spinners = document.querySelectorAll('.js-custom-cart-qty-spinner');

Expand All @@ -35,6 +42,12 @@ const cartController = () => {
});
};

/**
* Initializes the cart controller by attaching event handlers to relevant DOM elements.
* @public
* @function
* @memberof cartController
*/
const init = () => {
const {
discountCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const addVoucherToCartRequest = (payload) => {
required: true,
},
};

/**
* Validates the payload against the payload definition.
* @throws {Error} Throws an error if the payload is invalid.
Expand Down
38 changes: 24 additions & 14 deletions _dev/js/theme/core/cart/store/cartStateStore.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,76 @@
/**
* Represents the state of the cart.
* @typedef {Object} state
* @property {string} errorMsg - The error message related to the cart state.
* @property {boolean} isUpdateOperation - Indicates whether the cart is in an update operation.
* @property {boolean} hasError - Indicates whether an error has occurred in the cart.
*/
const state = {
errorMsg: '',
isUpdateOperation: false,
hasError: false,
};

/**
* Store for cart state
* Store for managing the state of the cart.
* @module
* @returns {object}
* @returns {object} Object with methods to interact with the cart state.
*/
const cartStateStore = () => {
/**
* Sets the error message
* Sets the error message in the cart state.
* @method setErrorMsg
* @public
* @param {string} value
* @param {string} value - The error message to set.
* @returns {void}
*/
const setErrorMsg = (value) => {
state.errorMsg = value;
};

/**
* Returns the error message
* Gets the current error message from the cart state.
* @method getErrorMsg
* @public
* @return {string}
* @returns {string} The current error message.
*/
const getErrorMsg = () => state.errorMsg;

/**
* Sets the isUpdateOperation value
* Sets the isUpdateOperation value in the cart state.
* @method setIsUpdateOperation
* @public
* @param {boolean} value
* @param {boolean} value - The value to set for isUpdateOperation.
* @returns {void}
*/
const setIsUpdateOperation = (value) => {
state.isUpdateOperation = value;
};

/**
* Returns the isUpdateOperation value
* Gets the current value of isUpdateOperation from the cart state.
* @method getIsUpdateOperation
* @public
* @return {boolean}
* @returns {boolean} The current value of isUpdateOperation.
*/
const getIsUpdateOperation = () => state.isUpdateOperation;

/**
* Sets the hasError value
* Sets the hasError value in the cart state.
* @method setHasError
* @public
* @param {boolean} value
* @param {boolean} value - The value to set for hasError.
* @returns {void}
*/
const setHasError = (value) => {
state.hasError = value;
};

/**
* Returns the hasError value
* Gets the current value of hasError from the cart state.
* @method getHasError
* @public
* @return {boolean}
* @returns {boolean} The current value of hasError.
*/
const getHasError = () => state.hasError;

Expand Down

0 comments on commit 82fb242

Please sign in to comment.