1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = useSelectChangeNotifiers;
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 | var _useMessageBus = _interopRequireDefault(require("../utils/useMessageBus"));
|
10 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
11 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
12 | const SELECTION_CHANGE_TOPIC = 'select:change-selection';
|
13 | const HIGHLIGHT_CHANGE_TOPIC = 'select:change-highlight';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function useSelectChangeNotifiers() {
|
20 | const messageBus = (0, _useMessageBus.default)();
|
21 | const notifySelectionChanged = React.useCallback(newSelectedItems => {
|
22 | messageBus.publish(SELECTION_CHANGE_TOPIC, newSelectedItems);
|
23 | }, [messageBus]);
|
24 | const notifyHighlightChanged = React.useCallback(newHighlightedItem => {
|
25 | messageBus.publish(HIGHLIGHT_CHANGE_TOPIC, newHighlightedItem);
|
26 | }, [messageBus]);
|
27 | const registerSelectionChangeHandler = React.useCallback(handler => {
|
28 | return messageBus.subscribe(SELECTION_CHANGE_TOPIC, handler);
|
29 | }, [messageBus]);
|
30 | const registerHighlightChangeHandler = React.useCallback(handler => {
|
31 | return messageBus.subscribe(HIGHLIGHT_CHANGE_TOPIC, handler);
|
32 | }, [messageBus]);
|
33 | return {
|
34 | notifySelectionChanged,
|
35 | notifyHighlightChanged,
|
36 | registerSelectionChangeHandler,
|
37 | registerHighlightChangeHandler
|
38 | };
|
39 | } |
\ | No newline at end of file |