1 | import * as React from 'react';
|
2 | import useMessageBus from '../utils/useMessageBus';
|
3 | const SELECTION_CHANGE_TOPIC = 'select:change-selection';
|
4 | const HIGHLIGHT_CHANGE_TOPIC = 'select:change-highlight';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export default function useSelectChangeNotifiers() {
|
11 | const messageBus = useMessageBus();
|
12 | const notifySelectionChanged = React.useCallback(newSelectedItems => {
|
13 | messageBus.publish(SELECTION_CHANGE_TOPIC, newSelectedItems);
|
14 | }, [messageBus]);
|
15 | const notifyHighlightChanged = React.useCallback(newHighlightedItem => {
|
16 | messageBus.publish(HIGHLIGHT_CHANGE_TOPIC, newHighlightedItem);
|
17 | }, [messageBus]);
|
18 | const registerSelectionChangeHandler = React.useCallback(handler => {
|
19 | return messageBus.subscribe(SELECTION_CHANGE_TOPIC, handler);
|
20 | }, [messageBus]);
|
21 | const registerHighlightChangeHandler = React.useCallback(handler => {
|
22 | return messageBus.subscribe(HIGHLIGHT_CHANGE_TOPIC, handler);
|
23 | }, [messageBus]);
|
24 | return {
|
25 | notifySelectionChanged,
|
26 | notifyHighlightChanged,
|
27 | registerSelectionChangeHandler,
|
28 | registerHighlightChangeHandler
|
29 | };
|
30 | } |
\ | No newline at end of file |