Skip to content

Commit 3fb9da3

Browse files
[TSVB] Remove jQuery dependency from plugins (#83809) (#84302)
* Use rxjs instead of jquery for eventBus. * Fix comments * Removed one check because property is private. * Resolve comments Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
1 parent 0431706 commit 3fb9da3

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/plugins/vis_type_timeseries/public/application/visualizations/lib/active_cursor.js renamed to src/plugins/vis_type_timeseries/public/application/visualizations/lib/active_cursor.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
// TODO: Remove bus when action/triggers are available with LegacyPluginApi or metric is converted to Embeddable
21-
import $ from 'jquery';
20+
import { Subject } from 'rxjs';
21+
import { PointerEvent } from '@elastic/charts';
2222

23-
export const ACTIVE_CURSOR = 'ACTIVE_CURSOR';
24-
25-
export const eventBus = $({});
23+
export const activeCursor$ = new Subject<PointerEvent>();

src/plugins/vis_type_timeseries/public/application/visualizations/views/timeseries/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
} from '@elastic/charts';
3535
import { EuiIcon } from '@elastic/eui';
3636
import { getTimezone } from '../../../lib/get_timezone';
37-
import { eventBus, ACTIVE_CURSOR } from '../../lib/active_cursor';
37+
import { activeCursor$ } from '../../lib/active_cursor';
3838
import { getUISettings, getChartsSetup } from '../../../../services';
3939
import { GRID_LINE_CONFIG, ICON_TYPES_MAP, STACKED_OPTIONS } from '../../constants';
4040
import { AreaSeriesDecorator } from './decorators/area_decorator';
@@ -54,7 +54,7 @@ const generateAnnotationData = (values, formatter) =>
5454
const decorateFormatter = (formatter) => ({ value }) => formatter(value);
5555

5656
const handleCursorUpdate = (cursor) => {
57-
eventBus.trigger(ACTIVE_CURSOR, cursor);
57+
activeCursor$.next(cursor);
5858
};
5959

6060
export const TimeSeries = ({
@@ -73,16 +73,16 @@ export const TimeSeries = ({
7373
const chartRef = useRef();
7474

7575
useEffect(() => {
76-
const updateCursor = (_, cursor) => {
76+
const updateCursor = (cursor) => {
7777
if (chartRef.current) {
7878
chartRef.current.dispatchExternalPointerEvent(cursor);
7979
}
8080
};
8181

82-
eventBus.on(ACTIVE_CURSOR, updateCursor);
82+
const subscription = activeCursor$.subscribe(updateCursor);
8383

8484
return () => {
85-
eventBus.off(ACTIVE_CURSOR, undefined, updateCursor);
85+
subscription.unsubscribe();
8686
};
8787
}, []);
8888

0 commit comments

Comments
 (0)