Skip to content

Commit

Permalink
[TSVB] Remove jQuery dependency from plugins (#83809) (#84302)
Browse files Browse the repository at this point in the history
* Use rxjs instead of jquery for eventBus.

* Fix comments

* Removed one check because property is private.

* Resolve comments

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
VladLasitsa and kibanamachine authored Nov 26, 2020
1 parent 0431706 commit 3fb9da3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
* under the License.
*/

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

export const ACTIVE_CURSOR = 'ACTIVE_CURSOR';

export const eventBus = $({});
export const activeCursor$ = new Subject<PointerEvent>();
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from '@elastic/charts';
import { EuiIcon } from '@elastic/eui';
import { getTimezone } from '../../../lib/get_timezone';
import { eventBus, ACTIVE_CURSOR } from '../../lib/active_cursor';
import { activeCursor$ } from '../../lib/active_cursor';
import { getUISettings, getChartsSetup } from '../../../../services';
import { GRID_LINE_CONFIG, ICON_TYPES_MAP, STACKED_OPTIONS } from '../../constants';
import { AreaSeriesDecorator } from './decorators/area_decorator';
Expand All @@ -54,7 +54,7 @@ const generateAnnotationData = (values, formatter) =>
const decorateFormatter = (formatter) => ({ value }) => formatter(value);

const handleCursorUpdate = (cursor) => {
eventBus.trigger(ACTIVE_CURSOR, cursor);
activeCursor$.next(cursor);
};

export const TimeSeries = ({
Expand All @@ -73,16 +73,16 @@ export const TimeSeries = ({
const chartRef = useRef();

useEffect(() => {
const updateCursor = (_, cursor) => {
const updateCursor = (cursor) => {
if (chartRef.current) {
chartRef.current.dispatchExternalPointerEvent(cursor);
}
};

eventBus.on(ACTIVE_CURSOR, updateCursor);
const subscription = activeCursor$.subscribe(updateCursor);

return () => {
eventBus.off(ACTIVE_CURSOR, undefined, updateCursor);
subscription.unsubscribe();
};
}, []);

Expand Down

0 comments on commit 3fb9da3

Please sign in to comment.