@vtex/order-manager
Advanced tools
Comparing version 0.4.0 to 0.4.1-1
@@ -10,2 +10,6 @@ # Changelog | ||
## [0.4.1-1] - 2021-04-20 | ||
## [0.4.1-0] - 2021-04-20 | ||
## [0.4.0] - 2021-04-20 | ||
@@ -12,0 +16,0 @@ ### Added |
/*! | ||
* @vtex/order-manager v0.4.0 | ||
* @vtex/order-manager v0.4.1-1 | ||
* (c) VTEX | ||
@@ -7,3 +7,3 @@ * Released under the MIT License. | ||
import React, { createContext, useRef, useLayoutEffect, useState, useMemo, useContext, useEffect, useReducer } from 'react'; | ||
import React, { createContext, useState, useRef, useLayoutEffect, useMemo, useContext, useEffect, useReducer } from 'react'; | ||
@@ -404,16 +404,17 @@ // Adapted from https://github.com/BalassaMarton/sequential-task-queue/blob/master/src/sequential-task-queue.ts | ||
const OrderQueueContext = createContext(undefined); | ||
const useQueueStatus = (listen) => { | ||
const queueStatus = useRef('Fulfilled'); | ||
const useQueueStatus = () => { | ||
const { status } = useOrderQueue(); | ||
return status; | ||
}; | ||
const OrderQueueProvider = ({ children, }) => { | ||
const [queue] = useState(() => new TaskQueue()); | ||
const status = useRef('Fulfilled'); | ||
useLayoutEffect(() => { | ||
const unlisten = listen('Pending', () => (queueStatus.current = 'Pending')); | ||
const unlisten = queue.listen('Pending', () => (status.current = 'Pending')); | ||
return unlisten; | ||
}, [listen]); | ||
}, [queue]); | ||
useLayoutEffect(() => { | ||
const unlisten = listen('Fulfilled', () => (queueStatus.current = 'Fulfilled')); | ||
const unlisten = queue.listen('Fulfilled', () => (status.current = 'Fulfilled')); | ||
return unlisten; | ||
}, [listen]); | ||
return queueStatus; | ||
}; | ||
const OrderQueueProvider = ({ children, }) => { | ||
const [queue] = useState(() => new TaskQueue()); | ||
}, [queue]); | ||
const value = useMemo(() => ({ | ||
@@ -423,3 +424,4 @@ enqueue: queue.enqueue.bind(queue), | ||
isWaiting: queue.isWaiting.bind(queue), | ||
}), [queue]); | ||
status, | ||
}), [queue, status]); | ||
return (React.createElement(OrderQueueContext.Provider, { value: value }, children)); | ||
@@ -439,4 +441,4 @@ }; | ||
const { showToast, toastState } = useToast(); | ||
const { enqueue, listen } = useOrderQueue(); | ||
const queueStatusRef = useQueueStatus(listen); | ||
const { enqueue } = useOrderQueue(); | ||
const queueStatusRef = useQueueStatus(); | ||
const clearOrderFormMessages = useClearOrderFormMessages(); | ||
@@ -567,4 +569,3 @@ useEffect(() => { | ||
const [orderFormLoading, setOrderFormLoading] = useState(!shouldUseLocalOrderForm); | ||
const { listen } = useOrderQueue(); | ||
const queueStatusRef = useQueueStatus(listen); | ||
const queueStatusRef = useQueueStatus(); | ||
useEffect(() => { | ||
@@ -571,0 +572,0 @@ if (loading || error || !data) { |
/*! | ||
* @vtex/order-manager v0.4.0 | ||
* @vtex/order-manager v0.4.1-1 | ||
* (c) VTEX | ||
@@ -411,16 +411,17 @@ * Released under the MIT License. | ||
const OrderQueueContext = React.createContext(undefined); | ||
const useQueueStatus = (listen) => { | ||
const queueStatus = React.useRef('Fulfilled'); | ||
const useQueueStatus = () => { | ||
const { status } = useOrderQueue(); | ||
return status; | ||
}; | ||
const OrderQueueProvider = ({ children, }) => { | ||
const [queue] = React.useState(() => new TaskQueue()); | ||
const status = React.useRef('Fulfilled'); | ||
React.useLayoutEffect(() => { | ||
const unlisten = listen('Pending', () => (queueStatus.current = 'Pending')); | ||
const unlisten = queue.listen('Pending', () => (status.current = 'Pending')); | ||
return unlisten; | ||
}, [listen]); | ||
}, [queue]); | ||
React.useLayoutEffect(() => { | ||
const unlisten = listen('Fulfilled', () => (queueStatus.current = 'Fulfilled')); | ||
const unlisten = queue.listen('Fulfilled', () => (status.current = 'Fulfilled')); | ||
return unlisten; | ||
}, [listen]); | ||
return queueStatus; | ||
}; | ||
const OrderQueueProvider = ({ children, }) => { | ||
const [queue] = React.useState(() => new TaskQueue()); | ||
}, [queue]); | ||
const value = React.useMemo(() => ({ | ||
@@ -430,3 +431,4 @@ enqueue: queue.enqueue.bind(queue), | ||
isWaiting: queue.isWaiting.bind(queue), | ||
}), [queue]); | ||
status, | ||
}), [queue, status]); | ||
return (React__default['default'].createElement(OrderQueueContext.Provider, { value: value }, children)); | ||
@@ -446,4 +448,4 @@ }; | ||
const { showToast, toastState } = useToast(); | ||
const { enqueue, listen } = useOrderQueue(); | ||
const queueStatusRef = useQueueStatus(listen); | ||
const { enqueue } = useOrderQueue(); | ||
const queueStatusRef = useQueueStatus(); | ||
const clearOrderFormMessages = useClearOrderFormMessages(); | ||
@@ -574,4 +576,3 @@ React.useEffect(() => { | ||
const [orderFormLoading, setOrderFormLoading] = React.useState(!shouldUseLocalOrderForm); | ||
const { listen } = useOrderQueue(); | ||
const queueStatusRef = useQueueStatus(listen); | ||
const queueStatusRef = useQueueStatus(); | ||
React.useEffect(() => { | ||
@@ -578,0 +579,0 @@ if (loading || error || !data) { |
{ | ||
"name": "@vtex/order-manager", | ||
"version": "0.4.0", | ||
"version": "0.4.1-1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "cdn": "dist/index.umd.js", |
@@ -1,3 +0,2 @@ | ||
import type { FC, ReactNode } from 'react'; | ||
import React from 'react'; | ||
import type { FC, ReactNode, RefObject } from 'react'; | ||
import type { OrderForm, QueueStatus } from './typings'; | ||
@@ -10,2 +9,3 @@ import type { CancellablePromiseLike } from './modules/SequentialTaskQueue'; | ||
isWaiting: (id: string) => boolean; | ||
status: RefObject<QueueStatus>; | ||
} | ||
@@ -15,3 +15,3 @@ interface OrderQueueProviderProps { | ||
} | ||
export declare const useQueueStatus: (listen: ListenFunction) => React.MutableRefObject<QueueStatus>; | ||
export declare const useQueueStatus: () => RefObject<QueueStatus>; | ||
export declare const OrderQueueProvider: FC<OrderQueueProviderProps>; | ||
@@ -18,0 +18,0 @@ export declare function useOrderQueue<O extends OrderForm>(): Context<O>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2569
198455
49