@shopgate/engage
Version:
Shopgate's ENGAGE library.
27 lines • 2.43 kB
JavaScript
import{createSelector}from'reselect';/**
* Retrieves the orders state from the store.
* @param {Object} state The current application state.
* @return {Object} The orders state.
*/var getOrdersState=function getOrdersState(state){return state.orders||{};};/**
* Retrieves the ordersById state from the store.
* @param {Object} state The current application state.
* @return {Object} The orders state.
*/var getOrdersByIdState=function getOrdersByIdState(state){return getOrdersState(state).ordersById||{};};/**
* Retrieves the ordersByNumber state from the store.
* @param {Object} state The current application state.
* @return {Object} The orders state.
*/var getOrdersByNumberState=function getOrdersByNumberState(state){return getOrdersState(state).ordersByNumber||{};};/**
* Retrieves the orders from the store.
* @param {Object} state The current application state.
* @return {Object} The orders state.
*/export var getOrders=createSelector(getOrdersState,getOrdersByNumberState,function(orders,ordersByNumber){return orders.orders.orders.map(function(orderNumber){var _ordersByNumber$order;return(_ordersByNumber$order=ordersByNumber[orderNumber])===null||_ordersByNumber$order===void 0?void 0:_ordersByNumber$order.order;});});/**
* Retrieves total count of orders from the store.
* @param {Object} state The current application state.
* @return {Object} The orders state.
*/export var getTotalOrderCount=function getTotalOrderCount(state){return getOrdersState(state).orders.totalOrderCount;};/**
* Creates the selector that retrieves an order by its number.
* @returns {Function}
*/export var makeGetOrderById=function makeGetOrderById(){return createSelector(function(state,props){return props.orderId;},getOrdersByIdState,function(orderId,orders){var _orders$orderId;return(orders===null||orders===void 0?void 0:(_orders$orderId=orders[orderId])===null||_orders$orderId===void 0?void 0:_orders$orderId.order)||null;});};/**
* Creates the selector that retrieves an order by its number.
* @returns {Function}
*/export var makeGetOrderByNumber=function makeGetOrderByNumber(){return createSelector(function(state,props){return props.orderNumber;},getOrdersByNumberState,function(orderNumber,orders){var _orders$orderNumber;return(orders===null||orders===void 0?void 0:(_orders$orderNumber=orders[orderNumber])===null||_orders$orderNumber===void 0?void 0:_orders$orderNumber.order)||null;});};