| 1 |
import { useService } from "@web/core/utils/hooks"; |
| 2 |
import { useComponent, useEffect } from "@odoo/owl"; |
| 3 |
|
| 4 |
export function useBarcodeReader(callbackMap, exclusive = false) { |
| 5 |
const current = useComponent(); |
| 6 |
const barcodeReader = useService("barcode_reader"); |
| 7 |
if (barcodeReader) { |
| 8 |
for (const [key, callback] of Object.entries(callbackMap)) { |
| 9 |
callbackMap[key] = callback.bind(current); |
| 10 |
} |
| 11 |
useEffect( |
| 12 |
() => barcodeReader.register(callbackMap, exclusive), |
| 13 |
() => [] |
| 14 |
); |
| 15 |
} |
| 16 |
} |